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.
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?
Alternatively, how can I make libgcc and libstdc++ a static part of libpolyml?
Makarius
* > 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"
I wouldn't rely on toolchain advice that is more than five years old.
Statically linking libgcc and libstdc++ will cause more problems than it solves unless you can ensure that everything in the process links statically against those libraries, which means no dlopen and no reliance on system libraries written in C++. Worse, these problems manifest even when running on the exact same system which were used for building (e.g., exception handling is not working properly).
It may be that this is needed on Ubuntu, but other distributions have backwards compatibility for the C/C++ runtime across releases, so that you only have to compile on the oldest release you want to support.
There is also a hybrid linking model for libstdc++, where only newer bits are linked statically, so that compatibility with the system libstdc++ is preserved and no new version of libstdc++ is needed at run time. But indiscriminate static linking is a bad idea, particularly for code which has any kind of plug-in framework.
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