Shared library with rootcint

Hi,

I am trying to generate a shared library for use interactively in Root with rootcint. Apologies if I’ve missed a recent post where this is described, the most recent comprehensive Root Talk discussion on it I could find is from several years ago.

I have getnu.cc and getnu.h, straightforward C code except it uses GMP. I have generated a shared library and linked successfully against it with g++ but haven’t been able to generate a library which Root likes. I load the library with gSystem->Load(“libgetnu.so”) but get the error:

dlopen error: /usr/local/bin/cernroot/rootv5.20/lib/libgetnu.so: cannot open shared object file: No such file or directory
Load Error: Failed to load Dynamic link library /usr/local/bin/cernroot/rootv5.20/lib/libgetnu.so
(int)(-1)
*** Interpreter error recovered ***
*** Interpreter error recovered ***

despite the fact that the library is certainly there. This is what I do in Root v5.20:

  1. nulinkdef.h contains:

#ifdef CINT
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ defined_in getnu.h
#endif

  1. rootcint -f getnuDict.C -c [-p] getnu.h nulinkdef.h

[I’ve tried with and without the -p flag]

  1. g++ -O -fPIC -I /usr/local/bin/cernroot/rootv5.22/include -c -o getnuDict.o getnuDict.C

  2. g++ -O -fPIC -o getnu.o -c getnu.cc

  3. g++ -shared -lgmp -lgmpxx -o libgetnu.so getnu.o getnuDict.o

Thanks in advance for any help,

Chris

Hi Again,

Maybe this wil lhelp illustrate what I am trying to do. In principle I believe ACLiC should work. In v5.20:

root [0] gSystem->AddIncludePath(" -I/home/potter/analysis/dilepton/getnu")
root [1] gSystem->AddLinkedLibs("-L/usr/lib64 -lgmp")
root [2] .x getnu.cc++

but I get errors

But the file /home/potter/analysis/dilepton/getnu/./getnu.h is absolutely there. Thanks for your help,

Chris

Hi Chris,

Are the file ‘readable’? Are they on a remote file system that may or may not be update ‘fast’ enough? Are you sure you are not mixing 32bit and 64bit builds? Can you provide a tar file containing an example reproducing this problem?

Cheers,
Philippe.

Hi Philippe,

Thanks for your reply.

The files are not on a remote system, they are on the internal hard drive. It does seem that Root does not see them. It’s possible I’m mixing 32 and 64 bit builds - but I don’t see how. I’m using the Root binary that came with the 64 bit build of Root downloaded from the Root webpage.

I tried with both ACLiC and rootcint on a very simple set of test files with the same results. In test.cc:

void test(bool x, double y) { if(x) y+=4.; }

In test.h:

In ACLiC I get:

root [0] gSystem->AddIncludePath(" -I/home/potter/temp")
root [0] .x test.cc++
Info in <TUnixSystem::ACLiC>: creating shared library /home/potter/temp/./test_cc.so
Warning: link requested for unknown srcfile /home/potter/temp/./test.h file08wFgXlinkdef.h:8:
Error: Function test() is not defined in current scope  :0:

Trying with rootcint I get:

potter@heracles > rootcint -f testDict.C -c test.h testlinkdef.h 
potter@heracles > g++ -O -fPIC -I /usr/local/bin/cernroot/rootv5.22/include -c -o testDict.o testDict.C
potter@heracles > g++ -O -fPIC -o test.o -c test.cc
potter@heracles > g++ -O -fPIC -I /usr/local/bin/cernroot/rootv5.22/include -c -o testDict.o testDict.C
root [0] gSystem->Load("libtest.so")
dlopen error: /home/potter/temp/./libtest.so: cannot open shared object file: No such file or directory
Load Error: Failed to load Dynamic link library /home/potter/temp/./libtest.so
(int)(-1)

Thanks for your help.

Chris

[quote=“pcanal”]Hi Chris,

Are the file ‘readable’? Are they on a remote file system that may or may not be update ‘fast’ enough? Are you sure you are not mixing 32bit and 64bit builds? Can you provide a tar file containing an example reproducing this problem?

Cheers,
Philippe.[/quote]

Hi,

Is /home/potter/temp a soft link?

In your compilation lines you do not show where you build the library.

Cheers,
Philippe