使用CMake和GCC 4.1.2链接到stdc ++ [英] Linking to stdc++ with CMake and GCC 4.1.2
问题描述
我正在开发一个库,需要确保它可以与4.1.2一起编译(我知道,这给我带来了很大的乐趣).因此,我在Fedora 14机器上下载,编译并安装了GCC41.
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.
现在在CMake中,我仅将以下内容更改为变量 CMAKE_CXX_COMPILER =/opt/gcc41/bin/c ++ 41 CMAKE_C_COMPILER =/opt/gcc41/bin/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)'
显然,它从.../include/c ++/4.5.1/中引入了include,但是我看不到它链接到哪个版本的库.
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?
推荐答案
使用CMake配置时,请在首次配置之前 指定编译器.使用环境变量CC和CXX指定C和C ++编译器:
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
从干净/空的构建树开始,以避免第一次使用不同的编译器运行CMake时出现陈旧的缓存条目. (在第一个CMake运行后,如果不重新启动,就无法更改编译器...)
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...)
这篇关于使用CMake和GCC 4.1.2链接到stdc ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!