Linking to stdc++ with CMake and GCC 4.1.2
I am developing开发者_JS百科 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?
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...)
Make your gcc version to default in Fedora:
./configure CC=/path/to/gcc/of/your/choice
精彩评论