链接到 stdc++使用 CMake 和 GCC 4.1.2
我正在开发一个库,需要确保它可以使用 4.1.2 进行编译(我知道,它没有给我带来任何乐趣)。因此,我在 Fedora 14 机器上下载、编译并安装了 GCC41。
现在在 CMake 中我只将以下内容更改为变量 CMAKE_CXX_COMPILER=/opt/gcc41/bin/c++41 CMAKE_C_COMPILER=/opt/gcc41/bin/gcc41
它编译得很好,但似乎使用了错误版本的标准库。我得到的错误看起来像这样:
/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/中提取包含内容,但我看不到它链接到哪个版本的库。
我有什么办法可以控制这个吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 CMake 配置时,请在首次配置之前指定编译器。使用环境变量 CC 和 CXX 指定 C 和 C++ 编译器:
从干净/空的构建树开始,以避免第一次使用不同编译器运行 CMake 时出现过时的缓存条目。 (在第一次 CMake 运行后,如果不重新开始,就无法更改编译器...)
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:
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...)
将您的 gcc 版本设置为 Fedora 中的默认版本:
Make your gcc version to default in Fedora: