Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link to specific stdc++ library

Tags:

c++

gcc

libstdc++

I have a c++ application which I am trying to build under Linux, it needs to be linked to a third party shared library, however this library has been built with a quite recent version of GCC/glibc (4.8.3/2.18). When I try and build my application using a less recent version of GCC/glibc (4.4.7/2.12), the linked phase of the build fails, with ld complaining of undefined references, which are references to functions defined in the newer libstdc++.

The third party has given me a precompiled version of libstdc++ and libgcc_s to use with the library, but how do I use these versions in my build?

How do I tell GCC to use the precompiled libraries instead of the system ones, while still using the system GCC?

I have tried using the "-nodefaultlibs" option and including "-lstdc++" and "-L" options, but it seems to have no effect on the undefined references.

Example of an error I get during linking:

undefined reference to std::__throw_bad_function_call()@GLIBCXX_3.4.14' undefined reference to std::length_error::~length_error()@GLIBCXX_3.4.15'

like image 777
Michael S Avatar asked Nov 10 '22 23:11

Michael S


1 Answers

I managed to get the application to build successfully by specifying the full path of the libstdc++ and libgcc_s shared objects in the objects list of the linking command (e.g. /home/mike/Downloads/libstdc++.so.6) . Going this way I didn't need to use any additional options such as "-nostdlibs" and only needed to ensure the linked shared objects were available via the LD_LIBRARY_PATH when running the application.

like image 197
Michael S Avatar answered Nov 14 '22 22:11

Michael S