views:

146

answers:

2

I wrote some custom c++ code and it works fine in ubuntu, but when I upload it to my server (which uses centos 5) its fails and says library is out of date. I googled all around and centos cannot use the latest libraries. How can I compile against the stl so that it is included in the binary and it doesn't matter that centos uses an old library?

P.S. I don't want to upload the source to the server and compile there.

+3  A: 

In your linking step, you can simply add the "-static" flag to gcc: http://gcc.gnu.org/onlinedocs/gcc-4.4.1/gcc/Link-Options.html#Link-Options

marshall_law
A: 
  1. You may install on your Ubuntu box the compiler that fits the version of the library on your server.

  2. You may ship your application with libstdc++.so taken from the system you compiled it at, provided you tune the linking so it gets loaded instead of centos' one.

  3. You may compile it statically. To do this, you should switch your compiler from g++ to

    gcc -lgcc_s -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic

Choose whatever you like. Note that approaches (2) and (3) may arise the problem of dependencies: your project (particularly, the stdc++ implementation that, being statically linked, is now a part of your app) may require some functions to present in the system libraries on centos. If there are no such functions, your application won't start. The reason why it can happen is that ubuntu system you're compiling at is newer, and forward compatibility is not preserved in linux libraries.

Pavel Shved