Adding shared libraries to ROOT?

Dear Rooters

I would like to add my own shared libraries to root/lib.
(This seems for me to be the easiest way to allow users to acces my libraries.)

As an exmaple I enclose code for MyClassA which can be compiled to “libMyClassA.so”.

How do I need to change the make file “Makefile4MyClassA” so that it compiles the
library “libMyClassA.so” in root/lib and adds the include files to root/include?

Best regards
Christian
myclass.tar.gz (2.15 KB)

Here’s a copy of a Makefile that I use (it works on linux with gcc/kai, cygwin with gcc, and mac). It was built using $ROOTSYS/test/Makefile.arch. It will build a shared library that includes a dictionary if the dictionary files are present that can be directly loaded into root or used to build standalone code.

Note that it would be nice if there was an official version of this Makefile that people could just grab (i.e. something that linked directoy against $ROOTSYS/test/Makefile.arch.

Cheers,
Charles

p.s. The directory structure is as follows

Top level:
shlib - where the so file will be
YourLibrary - where your code will live
src - source file directory
YourLibrary - include directory
dict - dictionary directory
objects - where .o files will be put
Makefile.txt (4.16 KB)

Dear Charles

Thank you for your Makefile, which I have just tried.
Sorrowly, I get the following error:

Makefile:150: objects/MyClassA.d: No such file or directory
Generating dependencies for src/MyClassA.cc
make: *** No rule to make target objects/MyClassA.o', needed by…/shlib/libMyClassA.dylib’. Stop.

Do you know what might be the reason?

Best regards
Christian

Are you running on a PowerPC or intel Mac?

Did you make an ‘objects’ directory?

Are your header files are ‘.hh’ and your source files are ‘.cc’?

Cheers,
Charles

Currently, I am using my new MacBook Pro Core 2 Duo :slight_smile:

I am attaching a file with the contents of MyClassA.

P.S.: In my own makefiles the first line is: include Makefile.arch
This saves me from having to add ifeq($(ARCH),…)…

Thank you
Christian
MyClassA.tar.gz (3.36 KB)

I just moved the files to the directories I mentioned, hit gmake, and it worked fine (on Cygwin using gcc). If this doesn’t work for you, then you are having a Mac issue (which should be solvable, but unfortunately not by me :blush: ).

Cheers,
Charles
MyClassA_rearranged.tar.gz (3.45 KB)

Thank you, at least there was some output, however, as you already mentioned, this seems to be a Mac-problem.
Your makefile has so many Mac-options, which I do not understand. Hopefully, someone else can help?

Here is the output:
Makefile:150: objects/MyClassA.d: No such file or directory
Generating dependencies for src/MyClassA.cc
g++ -g -pipe -W -Wall -Woverloaded-virtual -fsigned-char -fno-common -D__REGEXP -DG__UNIX -DG__SHAREDLIB -DG__ROOT -DG__REDIRECTIO -DG__OSFDLL -D_REENTRANT -Wno-long-double -I/Volumes/CoreData/ROOT/root/include -Iinclude -I…/include -IMyClassA -I…/MyClassA -c -o objects/MyClassA.o src/MyClassA.cc
Generating dictionary for MyClassA/MyClassA.hh objects/dict_MyClassA.o
/Volumes/CoreData/ROOT/root/bin/rootcint -f objects/dict_MyClassA.C -c -Idict -Iinclude -I…/include -IMyClassA -I…/MyClassA MyClassA.hh MyClassA_linkdef.h
g++ -c -g -pipe -W -Wall -Woverloaded-virtual -fsigned-char -fno-common -D__REGEXP -DG__UNIX -DG__SHAREDLIB -DG__ROOT -DG__REDIRECTIO -DG__OSFDLL -D_REENTRANT -Wno-long-double -I/Volumes/CoreData/ROOT/root/include -Iinclude -I…/include -IMyClassA -I…/MyClassA -o objects/dict_MyClassA.o objects/dict_MyClassA.C
g++ -g -dynamiclib -single_module -undefined dynamic_lookup -install_name …/shlib/libMyClassA.dylib objects/MyClassA.o objects/dict_MyClassA.o -o …/shlib/libMyClassA.dylib
ld: can’t create output file: …/shlib/libMyClassA.dylib (No such file or directory, errno = 2)
/usr/bin/libtool: internal link edit command failed
make: *** […/shlib/libMyClassA.dylib] Error 1

Best regards
Christian

Do you have a ‘shlib’ directory parallel to the ‘MyClassA’ directory?

Charles

Yes, but now I deleted it. The error remains the same.

Christian

[quote=“cstrato”]Yes, but now I deleted it. The error remains the same.

Christian[/quote]

Don’t delete it; you need it.

The error

ld: can't create output file: ../shlib/libMyClassA.dylib (No such file or directory, errno = 2) 

seems to indicate that it can’t create the file, suggesting that you do not have a ‘shlib’ directory parallel to your MyClassA directory.

In other words,

cplager@PointyIII> cd parentDir/
cplager@PointyIII> ls -lcF
total 0
drwxr-xr-x+ 7 cplager None 0 Jan 17 14:31 MyClassA/
drwxr-xr-x+ 2 cplager None 0 Jan 17 14:41 shlib/
cplager@PointyIII> 
cplager@PointyIII> cd MyClassA/
cplager@PointyIII> gmake
Makefile:150: objects/MyClassA.d: No such file or directory
....

Now I understand, and now everything works fine, with the exception that “make clean” does not delete libXX.so but only libXX.dylib.

/--------------------------------------------------------/

Now that everything works I would like to come back to my initial question:

In order to make my shared libraries accessible to other users w/o having to add a special directory to $PATH,
I would like to add my libraries to the root directory “root/lib”. Is there any reason why this would be a bad idea?
I suupose that I need also to add my *.h files to “root/include”. Is this correct?

Best regards
Christian

[quote=“cstrato”]Now that everything works I would like to come back to my initial question:

In order to make my shared libraries accessible to other users w/o having to add a special directory to $PATH,
I would like to add my libraries to the root directory “root/lib”. Is there any reason why this would be a bad idea?
I suupose that I need also to add my *.h files to “root/include”. Is this correct?
[/quote]

I’m just a Joe off the street, so weight my advice accordingly. Personally, I think you are better off not putting your files along with the standard Root distribution. That will probably just confuse the people you work with as to what is Root and what is your code.

I’d make a separate directory tree that has your code and libraries. If people are using inside Root, then they can just load it and if they are using it to build against, they just need to setup their makefile to find your stuff.

Cheers,
   Charles

Theoretically, this would be users who should not be forced to do anything in order to use my libraries!!!
This is the reason why I think of putting my libraries in the root/lib directory.

Christian