Hi Makarius,
On 23/12/17 14:24, Makarius wrote:
Dear experts on building and linking C++ applications,
according to the blog "Creating portable Linux binaries" http://insanecoding.blogspot.de/2012/07/creating-portable-linux-binaries.htm... the following options could make the poly executable more portable accross different Linux versions:
CFLAGS="-static-libgcc -static-libstdc++ -Wl,-Bstatic -lgmp -Wl,-Bdynamic"
On the surface this works fine on x86_64-linux (Ubuntu 16.04 LTS), but there is a remaining dependency on libpolyml.so, which itself depends on dynamic gcc and stdc++ libraries.
When you build with the above CFLAGS, does objdump -p <install-dir>/bin/poly show no NEEDED entry for libgcc and libstdc++ in the dynamic section? I.e. did this actually cause these libraries to be statically linked? (They are still present for me if I use the above -static-... options.)
"-Wl,-Bstatic -lgmp -Wl,-Bdynamic" causes configure to fail for me. That is not surprising because the packages for gmp only distribute shared object (.so) files - there is no archive (.a) file so static linking to gmp is not possible without building it myself. Presumably you have archive/object files for all the libraries you want to statically link?
Including "-lpolyml" next to "-lgmp" above does not work, probably because these options also apply to the build process of libpolyml itself.
How can I make libpolyml a static part of poly?
If you build Poly/ML with --disable-shared, libpolyml will always be statically linked: it has to be because no SO file is installed.
Even if Poly/ML is built with --enable-shared, the archive (.a) files are still installed. Therefore, regardless of how Poly/ML was built, you can produce an executable that statically links libpolyml by linking as follows:
gcc file.o \ -Wl,-Bstatic \ -L<install-dir>/lib -lpolymain -lpolyml \ -Wl,-Bdynamic \ -lpthread [-lffi] -lgmp -lm -ldl -lstdc++ -lgcc_s -lgcc
(-lffi required if --with-system-libffi was specified.) You can't use polyc in this case though.
Phil
Alternatively, how can I make libgcc and libstdc++ a static part of libpolyml?
Makarius _______________________________________________ polyml mailing list polyml at inf.ed.ac.uk http://lists.inf.ed.ac.uk/mailman/listinfo/polyml