Problem of loading libary in the run time

hi all, i am quite new at root. i have a question about loading library in a main() function, rather than compile with the library , Is this possible?

for example, if I run a root macro inside the root program, i can use gSystem->Load(“libRio”);
gSystem->Load(“libGeom”);
in the root macro.

but if i want to build a stand alone program, how can i load this library, when i try to do the same thing, i have such error message:

dlopen error: /home/zweng/root/lib/libRIO.so: undefined symbol: _ZTV11TCollection
Load Error: Failed to load Dynamic link library /home/zweng/root/lib/libRIO.so
dlopen error: /home/zweng/root/lib/libGeom.so: undefined symbol: _ZTI7TString
Load Error: Failed to load Dynamic link library /home/zweng/root/lib/libGeom.so

How can i deal with this problem? Thanks !

Hi,

In those cases, you also need to link or load libCore.so

Cheers,
Philippe.

[quote=“pcanal”]Hi,

In those cases, you also need to link or load libCore.so

Cheers,
Philippe.[/quote]

Thank you for your reply.
Actually i had already load the libCore.so and also libCint.so, but the error message still goes:

dlopen error: /home/zweng/root/lib/libRIO.so: undefined symbol: _ZTV11TCollection
Load Error: Failed to load Dynamic link library /home/zweng/root/lib/libRIO.so
dlopen error: /home/zweng/root/lib/libGeom.so: undefined symbol: _ZTI7TString
Load Error: Failed to load Dynamic link library /home/zweng/root/lib/libGeom.so
dlopen error: /home/zweng/root/lib/libMatrix.so: undefined symbol: gROOT
Load Error: Failed to load Dynamic link library /home/zweng/root/lib/libMatrix.so
Error in TCint::AutoLoadCallback: failure loading dependent library libMatrix.so for class TLorentzVector
dlopen error: /home/zweng/root/lib/libPhysics.so: undefined symbol: _ZTV7TString
Load Error: Failed to load Dynamic link library /home/zweng/root/lib/libPhysics.so
Error in TCint::AutoLoadCallback: failure loading library libPhysics.so for class TLorentzVector

Are there any thing i am missing, or this method simply can not be done?

Hi,

What is your code?

Philippe

[quote=“pcanal”]Hi,

What is your code?

Philippe[/quote]

Hi, thank you for your replying.

I have been trying to do these in a brand new project, and this is OK.
But when i try to add such code in my old code, there still problems so maybe there is something conflicing with each other ?

[quote]But when i try to add such code in my old code, there still problems so maybe there is something conflicing with each other ?[/quote]I have no clue :slight_smile: since I do not know what your old or even your new code look like :slight_smile:

Cheers,
Philippe.

[quote=“pcanal”][quote]But when i try to add such code in my old code, there still problems so maybe there is something conflicing with each other ?[/quote]I have no clue :slight_smile: since I do not know what your old or even your new code look like :slight_smile:

Cheers,
Philippe.[/quote]

i am sorry, the “old code” is a large project written by others, i just want to add some function on it.
the “new code” i mentiened is just a brand new main() function that do nothing but importing the library.
in the later case, i can know that such method is possible, but i do not know why it did not work in the old one.

Hi,

In the old code case, what are the error messages?

Philippe.

[quote=“pcanal”]Hi,

In the old code case, what are the error messages?

Philippe.[/quote]

Hi, i just try to add a function which will be invoked by the main function:

void vmc::VMCINIT(){

gSystem->Load("libCore.so");
gSystem->Load("libCint.so");
gSystem->Load("libRIO");

}

and when the programm run to this point, the error reads:
dlopen error: /home/zweng/root/lib/libRIO.so: undefined symbol: _ZTV11TCollection
Load Error: Failed to load Dynamic link library /home/zweng/root/lib/libRIO.so
dlopen error: /home/zweng/root/lib/libMatrix.so: undefined symbol: gROOT
Load Error: Failed to load Dynamic link library /home/zweng/root/lib/libMatrix.so
Error in TCint::AutoLoadCallback: failure loading dependent library libMatrix.so for class TLorentzVector
dlopen error: /home/zweng/root/lib/libPhysics.so: undefined symbol: _ZTV7TString
Load Error: Failed to load Dynamic link library /home/zweng/root/lib/libPhysics.so
Error in TCint::AutoLoadCallback: failure loading library libPhysics.so for class TLorentzVector

When i try to import other library simily message appears.

But when i do this in a brand new code, this process is OK.

Thank you for your helping!

Cheers

[quote=“pcanal”]Hi,

In the old code case, what are the error messages?

Philippe.[/quote]

i just realize that in the case of the new code, i use root-config --libs to load the basic root library in the compiler

but in the old project, there is already a -static option in the linking command so maybe this prevent the linking of the basic root library , and i do not know how to link a share library ( libGeom.so for example) when the -static option is on.

Will this be the problem?

Hi,

This is possible. You can build the root static library by doingcd $ROOTSYS; make static

Cheers,
Philippe.

[quote=“pcanal”]Hi,

This is possible. You can build the root static library by doingcd $ROOTSYS; make static

Cheers,
Philippe.[/quote]

Thank you for your reply. Actually i had already try to link the root static library in the compiling, but it seems not solve the problem. It seems to me that the static library do not include all the necessary function ? Or i need to specify the sub-library that built into the root static library ?

Hi,

You might need to add rootulibs="-Wl,-u,_G__cpp_setupG__Net \ -Wl,-u,_G__cpp_setupG__IO \ -Wl,-u,_G__cpp_setupG__Hist \ -Wl,-u,_G__cpp_setupG__Graf \ -Wl,-u,_G__cpp_setupG__G3D \ -Wl,-u,_G__cpp_setupG__GPad \ -Wl,-u,_G__cpp_setupG__Tree \ -Wl,-u,_G__cpp_setupG__Thread \ -Wl,-u,_G__cpp_setupG__Rint \ -Wl,-u,_G__cpp_setupG__PostScript \ -Wl,-u,_G__cpp_setupG__Matrix \ -Wl,-u,_G__cpp_setupG__Physics"

Cheers,
Philippe.