Linking to stdc++ with CMake and GCC 4.1.2

旧街凉风 提交于 2019-12-11 03:55:50

问题


I am developing a library and need to make sure it compiles with 4.1.2(I know, it brings me no pleasure). So on a Fedora 14 Machine I downloaded, compiled and installed GCC41.

Now in CMake I only change the following to variables CMAKE_CXX_COMPILER=/opt/gcc41/bin/c++41 CMAKE_C_COMPILER=/opt/gcc41/bin/gcc41

It compiles fine, but it seems to use the wrong version of the standard library. The error(s) I get look like this:

/opt/gcc41/bin/c++41 -Wall -Wold-style-cast -Wsign-compare -Wnon-virtual-dtor -Woverloaded-virtual -Wno-long-long -Wno-old-style-cast -g3 -O2 -ffast-math -mmmx -msse -msse2 -msse3 <OBJECT_FILES> -o <EXE_NAME> -rdynamic -lfreeimage -lcxcore -lcv -lml -lhighgui -lcvaux -llapack -lpthread -ltiff -lSM -lICE -lX11 -lXext -lrt -lz -ldl -ltiff  -lSM -lICE -lX11 -lXext -lrt -lz -ldl -lusb


In function `operator<< <std::char_traits<char> >':
/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/ostream:513: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)'

Apparently it pulls in the includes from .../include/c++/4.5.1/, but I can't see which version of the library it links to.

Is there any way I can control this?


回答1:


When you configure with CMake, specify the compilers before you configure for the first time. Use the environment variables CC and CXX to specify C and C++ compilers:

export CC=/opt/gcc41/bin/gcc41
export CXX=/opt/gcc41/bin/c++41
cmake ../source
make

Start with a clean/empty build tree in order to avoid stale cache entries from the first time CMake was run with a different compiler. (You can't change the compiler after the first CMake run without starting fresh...)




回答2:


Make your gcc version to default in Fedora:

./configure CC=/path/to/gcc/of/your/choice


来源:https://stackoverflow.com/questions/6581357/linking-to-stdc-with-cmake-and-gcc-4-1-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!