c++ - 在 CodeBlocks 中链接 Boost 库(使用 MinGW)

标签 c++ boost mingw

近三天来,我一直在尝试使用 mingw 在 CodeBlocks 中使 boost 库正常工作。在我自己设法解决的许多问题之间,现在我陷入困境,这让我发疯。

我已经用发送到 bjam 的不同标志多次构建了这个库但每次我在 CodeBlocks 中使用这些库时,我都会得到相同的结果。很多行有

undefined reference to `___gxx_personality_sj0'
undefined reference to `__Unwind_SjLj_Register'
undefined reference to `__Unwind_SjLj_Resume'
undefined reference to `__Unwind_SjLj_Unregister'

在人们开始抨击我之前,我在来这里之前已经搜索了问题所在。几乎所有的线程(herehere 和其他线程)都说这个问题是因为 boost 是用编译器构建的,现在我正在尝试在 CodeBlocks 中使用另一个不同的编译器。我查了一遍又一遍,我只有一个 MinGW安装可用。我检查了我的 Path变量,里面没有不需要的东西,只有我想使用的 MinGW 的 bin 文件夹。我没有任何 QT 安装,所以没有第二个 MinGW。另外,我下载了 CodeBlocks 没有捆绑的 MinGW。

下面我将列出我采取的步骤:

1) bootstrap.bat mingw构建 bjam

2) bjam --toolset=gcc "--prefix=<installpath>" install如所述here

3) 按照步骤 2) 中的链接执行其余步骤

4) 添加Boost.Filesystem , Boost.System , Boost.DateTime , Boost.ThreadBoost.Regex (Boost.Log 的依赖项取自 here )

5) 复制/粘贴 this example

我尝试构建时 CodeBlocks 使用的命令:

mingw32-g++.exe -Wall -fexceptions -g
-ID:\libs\boost\include\boost-1_51 -c D:\example\example\main.cpp -o obj\Debug\main.o

mingw32-g++.exe -LD:\libs\boost\lib -o bin\Debug\example.exe obj\Debug\main.o D:\libs\boost\lib\libboost_filesystem-mgw44-mt-d-1_51.a D:\libs\boost\lib\libboost_system-mgw44-mt-d-1_51.a D:\libs\boost\lib\libboost_date_time-mgw44-mt-d-1_51.a D:\libs\boost\lib\libboost_thread-mgw44-mt-1_51.a D:\libs\boost\lib\libboost_regex-mgw44-mt-d-1_51.a D:\libs\boost\lib\libboost_log_setup-mgw44-mt-d-1_51.a

这可能是什么原因造成的?

后来补充:

CodeBlocks 工具链可执行文件是:

c++ compiler: mingw32-g++.exe
linker for dynamic libs: mingw32-g++.exe
linker for static libs: ar.exe

所有 .EXE 都在它们应该在的位置,但添加此信息可能很重要。

最佳答案

修复了问题。在 Mankarse 问我 gcc 版本后,我检查了它与用于编译库 (4.4) 的版本相同。我决定升级到最新版本(4.7)再试一次。更新后,我注意到编译后的库名称中仍然有 mgw44,这让我觉得也许我确实安装了第二个 mingw。

检查了 Path 变量中的每个文件夹后,我得出的结论是几周前安装的 Strawberry Perl 也捆绑了一个 gcc 版本。在我删除它并从 sctratch 重建 boost 之后,错误消失了。

以后如果有人再遇到这个问题,确定自己只有一个mingw,再检查一遍就可以了:

  1. 从 Path 变量中删除带有 mingw exe 的 bin 文件夹

  2. 打开命令提示符并键入 g++。如果它显示类似 g++: fatal error: no input files 的内容,那么您安装了多个 mingw。

关于c++ - 在 CodeBlocks 中链接 Boost 库(使用 MinGW),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12072390/

相关文章:

c++ - CPP OpenCV - 尝试根据边缘裁剪图像

c++ - Boost 单元测试框架 : include main function of my codebase

windows - 如何在 Windows 上为 pkg-config 编写 *.pc 文件?

c++ - 如何将 BOOST_FOREACH 与仅支持 const_iterator 的容器一起使用?

C++ ASIO : Asynchronous sockets and threading

c++ - 警告已弃用的从字符串常量到 char * 的转换

c - 为什么我收到错误 "The program can' t start because msys-2.0.dll is missing from your computer”?有修复吗?

c++ - 构造一个空矩阵

c++ - 将 JavaFX Stage 嵌入到 C++ Windows 应用程序中

c++ - 我什么时候需要声明自己的析构函数?