链接到 stdc++使用 CMake 和 GCC 4.1.2

发布于 2024-11-19 00:39:23 字数 1145 浏览 9 评论 0原文

我正在开发一个库,需要确保它可以使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瞎闹 2024-11-26 00:39:23

使用 CMake 配置时,请在首次配置之前指定编译器。使用环境变量 CC 和 CXX 指定 C 和 C++ 编译器:

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

从干净/空的构建树开始,以避免第一次使用不同编译器运行 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:

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...)

黑白记忆 2024-11-26 00:39:23

将您的 gcc 版本设置为 Fedora 中的默认版本:

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

Make your gcc version to default in Fedora:

./configure CC=/path/to/gcc/of/your/choice
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文