简体   繁体   中英

Linking Statically with glibc and libstdc++

I'm writing a cross-platform application which is not GNU GPL compatible. The major problem I'm currently facing is that the application is linked dynamically with glibc and libstdc++, and almost every new major update to the libraries are not backwards compatible. Hence, random crashes are seen in my application.

As a workaround, I distribute binaries of my application compiled on several different systems (with different C/C++ runtime versions). But I want to do without this. So my question is, keeping licensing and everything in mind, can I link against glibc and libstdc++ statically? Also, will this cause issues with rtld?

You don't need to.

Copy the original libraries you linked against to a directory (../lib in this example) in your application folder.

Like:

my_app_install_path

  1. .bin
  2. lib
  3. documentation

Rename you app for something like app.bin. Substitute your app for a little shell script that sets the enviroment variable LD_LIBRARY_PATH to the library path (and concatenate the previous LD_LIBRARY_PATH contents, if any). Now ld should be able to find the dynamic libraries you linked against and you don't need to compile them statically to your executable.

Remember to comply with the LGPL adding the given attribution to the libraries and pointing in the documentation where the source can be downloaded.

glibc is under the LGPL. Under section 6. of LGPL 2.1 , you can distribute your program linked to the library provided you comply with one of five options. The first is to provide the source code of the library, along with the object code (source is optional, not required) of your own program, so it can be relinked with the library. You can alternatively provide a written offer of the same. Your own code does not have to be under the LGPL, and you don't have to release source.

libstdc++ is under the GPL, but with a major exception . You can basically just distribute under the license of your choice without providing source for either your own code or libstdc++. The only condition is that you compile normally, without eg proprietary modifications or plugins to GCC.

IANAL, and you should consider consulting one if you need real legal advice.

Specifying the option -static-libgcc to the linker would cause it to link against a static version of the C library, if available on the system. Otherwise it is ignored.

I must question what the heck you are doing with the poor library functions?

I have some cross platform software as well. It runs fine on Linux systems of all sorts. Build with the oldest version of software that you want to support. The glibc and libstdc++ libraries are really very backward compatible.

I have built on CentOS 4 and run it on RHEL 6 beta. No problems. I can build on stable Debian and run it on testing.

Now, I do sometimes have trouble with some libraries if I try to build on, say old Debian and try to run it on CentOS 5.4. That is usually due to distribution configuration choices that are different, like choosing threading or non-threading.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM