如何将vcpkg boost与MinGW链接

问题描述 投票:-1回答:1

我有一个在VS 2017社区下工作正常的代码。现在我不能再使用它了,我不得不切换到MinGW。 我使用MinGW编译了boost库,然后使用生成的库来链接我的程序:

  • Lib / libboost_program_options-mgw81-mt-d-x64-1_69.a(静态调试库)
  • Lib / libboost_program_options-mgw81-mt-x64-1_69.a(静态版本库)

这是我正在使用的命令:

g++.exe -DNDEBUG -DASCII -Wall -std=c++17 -static-libgcc -static-libstdc++ -L lib  -o prog.exe *.o -lboost_program_options-mgw81-mt-x64-1_69

这就是我得到的:

main.o:main.cpp:(.text+0x203): undefined reference to `__imp__ZN5boost15program_optionslsERSoRKNS0_19options_descriptionE'
main.o:main.cpp:(.text+0x3f9): undefined reference to `__imp__ZN5boost15program_options19options_description21m_default_line_lengthE'
main.o:main.cpp:(.text+0x406): undefined reference to `__imp__ZN5boost15program_options19options_description21m_default_line_lengthE'  
... (more lines like these)  

所有未定义的引用错误仅与boost::program_options调用有关(但我没有使用任何其他的boost库)。 我试过了:

  • 使用MinGW构建Boost源并链接到生成的静态库。
  • 使用vcpkg在我的计算机上使用的boost(.lib和.DLL)。 所有的尝试都给出了同样的错误。 我怎样才能解决这个问题 ? 环境 gcc 8.1.0 提升1.69 Windows 10 17134
c++ boost window mingw
1个回答
1
投票

问题: 似乎vcpkg($ {vcpkgRoot} / installed / x64-static / include)中包含的头文件不适用于MinGW。 原始命令g++.exe -DNDEBUG -I'c:/vcpkg/installed/x64-windows-static/include' -L . main.cpp -lboost_program_options-vc140-mt不起作用。这里我使用生成的boost_program_options-vc140-mt.lib文件和带有vcpkg的头文件。 我尝试使用MinGW构建Boost并使用.a文件:g++.exe -DNDEBUG -I'c:/vcpkg/installed/x64-windows-static/include' -L . main.cpp -lboost_program_options-mgw81-mt-x64-1_69也没有用。 但这个命令工作g++.exe -DNDEBUG -I'c:/boost-mingw/boost_1_69_0' -L . .\main.cpp -lboost_program_options-mgw81-mt-x64-1_69 这意味着标头特定于Visual Studio ..

© www.soinside.com 2019 - 2024. All rights reserved.