我有一个在VS 2017社区下工作正常的代码。现在我不能再使用它了,我不得不切换到MinGW。 我使用MinGW编译了boost库,然后使用生成的库来链接我的程序:
这是我正在使用的命令:
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库)。
我试过了:
问题:
似乎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 ..