链接错误:Windows上使用MinGW的Boost库

Linking Error: Boost Library on Windows using MinGW

本文关键字:MinGW Boost 错误 Windows 链接      更新时间:2023-10-16

我使用的是Windows 7 64x,并安装了MinGW。

我的目标是在Eclipse上使用boost库(这里:boost_program_options)。

boost库已正确安装,我可以在C:MinGWboost_1_53_0stagelib

下看到文件libboost_program_options-vc90-mt-gd-1_53.lib

我现在尝试通过转到Properties -> C/C++ Build -> Settings -> MinGW C++ Linker -> Libraries:

在Eclipse中链接它:

这里我输入Library Search Path (-L): C:MinGWboost_1_53_0stagelib对于Libraries (-l): boost_program_options-vc90-mt-gd-1_53

当尝试构建时,我得到以下错误消息:

11:06:54 **** Build of configuration Debug for project AP ****
make all 
Building file: ../src/HW1EX1.cpp
Invoking: GCC C++ Compiler
g++ -I"C:MinGWboost_1_53_0" -I"C:MinGWboost_1_53_0boostprogram_options" -I"C:MinGWboost_1_53_0boost" -I"C:MinGWboost_1_53_0boostprogram_optionsdetail" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/HW1EX1.d" -MT"src/HW1EX1.d" -o "src/HW1EX1.o" "../src/HW1EX1.cpp"
Finished building: ../src/HW1EX1.cpp
Building target: AP.exe
Invoking: MinGW C++ Linker
g++ -LC:MinGWboost_1_53_0stagelib -static-libgcc -o "AP.exe"  ./src/HW1EX1.o   -lboost_program_options-vc90-mt-gd-1_53
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lboost_program_options-vc90-mt-gd-1_53
collect2: ld returned 1 exit status
make: *** [AP.exe] Error 1
11:06:57 Build Finished (took 3s.80ms)
有谁知道我可能做错了什么吗?

感谢您的宝贵时间

您显然已经下载了使用Microsoft Visual c++编译器编译的二进制发行版(...-vc90-...是一个提示)。或者也许你已经自己构建了它,但你是用Microsoft Visual c++ Compiler完成的。您必须使用MinGW从源代码构建Boost,因为您不能混合由不同的c++编译器生成的c++代码。换句话说,在您的情况下,您不能使用MinGW链接到由Microsoft Visual c++ Compiler生成的库。

另外,我怀疑-LC:MinGWboost_1_53_0stagelib不会工作,因为有反斜杠,它没有引号。所以应该是-L"C:MinGWboost_1_53_0stagelib"或者-LC:/MinGW/boost_1_53_0/stage/lib。我更喜欢第二种变体,所以试着把向后斜杠改成向前斜杠,看看效果如何。还要仔细检查libboost_program_options-mgw46-1_53.a是否真的在C:MinGWboost_1_53_0stagelib