I am looking for advice on how to create portable LibraryLink binaries for Linux. I would like the same binary to work on many different Linux distributions, so the users of my package don't have to compile it from scratch. But unfortunately my knowledge about the issues involved (dynamic linking on Linux, compatibility between gcc versions, etc.) is quite limited.
- How should I compile the library to make sure it is as portable as possible?
- What should I check for to test for portability if I only have access to a single Linux computer? (Other than using
ldd
to check for dependencies.)
My library is written in C++11 (which may be a problem) and I compiled it on Ubuntu 15.10 with gcc 5.2.1. Reportedly it does not work on Ubuntu 14.04, and I am not sure why. ldd
lists only these dependencies:
$ ldd IGraphM.so
linux-vdso.so.1 => (0x00007fffecdf0000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f8e7a398000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8e79fce000)
/lib64/ld-linux-x86-64.so.2 (0x000056390dc55000)
Other than these, there are two libraries statically linked on the command line, igraph and gmp. I do this by using the "ExtraObjectFiles" -> {"$HOME/local/lib/libigraph.a", "$HOME/local/lib/libgmp.a"}
in CreateLibrary
. This just appends the two .a
files to the end of the gcc
command line.
I compiled both igraph and gmp myself on the same machine.
Any hints, comments, pointers, etc. would be most welcome!
More specific questions:
- Can it cause problems that I am linking to my own gmp version given that the Mathematica kernel already links to its own gmp?
- Are there specific requirements on the gcc versions that can be used with LibraryLink and Mathematica 10.x? Does the answer change for C++11 or C++98 vs just plain C?
ldd
didn't list libstdc++. How can I tell which libstdc++ is being used? Is it the one that ships with Mathematica (since the kernel process already loads it)? If yes, how does that impact on compatibility with the version of my compiler and standard library?
Finally, here's the command line that CreateLibrary
constructs:
/usr/bin/gcc -shared -o\
> "/home/szhorvat/Repos/IGraphM/IGraphM/LibraryResources/Linux-x86-64/Working\
> -ubuntu-vb-2054-821005440-1/IGraphM.so" -m64 -fPIC -O2 -std=c++11 \
> -I"/usr/local/Wolfram/Mathematica/10.3/SystemFiles/IncludeFiles/C"\
> -I"/usr/local/Wolfram/Mathematica/10.3/SystemFiles/Links/MathLink/Developer\
> Kit/Linux-x86-64/CompilerAdditions" -I"$HOME/local/include"\
> -I"/home/szhorvat/Repos/IGraphM/IGraphM/LTemplate/IncludeFiles"\
> "/home/szhorvat/Repos/IGraphM/IGraphM/LibraryResources/Source/LTemplate-IGr\
> aphM.cpp"\
> "/home/szhorvat/Repos/IGraphM/IGraphM/LibraryResources/Source/IGlobal.cpp"\
> "$HOME/local/lib/libigraph.a" "$HOME/local/lib/libgmp.a"\
> -L"/usr/local/Wolfram/Mathematica/10.3/SystemFiles/Links/MathLink/Developer\
> Kit/Linux-x86-64/CompilerAdditions"\
> -L"/usr/local/Wolfram/Mathematica/10.3/SystemFiles/Libraries/Linux-x86-64"\
> -L"$HOME/local/lib" 2>&1