链接错误:使用MinGW在Windows上启动库

时间:2013-04-24 09:18:44

标签: c++ eclipse boost linker mingw

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

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

正确安装了boost库,我可以在libboost_program_options-vc90-mt-gd-1_53.lib

下看到文件C:\MinGW\boost_1_53_0\stage\lib

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

在Eclipse中链接它

我在这里输入Library Search Path-L):C:\MinGW\boost_1_53_0\stage\lib 以及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:\MinGW\boost_1_53_0" -I"C:\MinGW\boost_1_53_0\boost\program_options" -I"C:\MinGW\boost_1_53_0\boost" -I"C:\MinGW\boost_1_53_0\boost\program_options\detail" -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:\MinGW\boost_1_53_0\stage\lib -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)

有没有人知道我可能做错了什么?

感谢您的时间

1 个答案:

答案 0 :(得分:2)

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

此外,我怀疑-LC:\MinGW\boost_1_53_0\stage\lib不起作用,因为有反斜杠而且没有引用。所以它应该是-L"C:\MinGW\boost_1_53_0\stage\lib"-LC:/MinGW/boost_1_53_0/stage/lib。我更喜欢第二种变体,所以尝试将反斜杠改为前进斜杠,看看它是怎么回事。另外,请仔细检查libboost_program_options-mgw46-1_53.a是否真的在C:\MinGW\boost_1_53_0\stage\lib