将 boost 与 Visual Studio 和 vcpkg 链接时出错
Error linking boost with Visual Studio and vcpkg
我正在尝试完成一项简单的任务,以检查在 Windows 中开发 "Linux apps" 有多容易。
我正在使用 vcpkg from Microsoft in order to setup headers and libs and crow ,一个使用 boost 作为驱动程序项目的 c++ http 服务器
来源简单
#include "crow.hpp"
int main()
{
crow::SimpleApp app;
CROW_ROUTE(app, "/")
([]() {
return "Hello world!";
});
app.port(18080).run();
}
我已经通过 vcpkg 下载了 boost 并使用 Visual Studio 对项目进行编码
cmake:
cmake_minimum_required (VERSION 3.8)
find_package(boost COMPONENTS filesystem system thread date_time REQUIRED)
message("this is ${Boost_INCLUDE_DIRS}")
include_directories ("C:\github.com\crow\include")
include_directories(SYSTEM PUBLIC ${Boost_INCLUDE_DIRS})
add_executable (engine "promo-engine-windows.cpp" "promo-engine-windows.h")
target_link_libraries(engine ${Boost_LIBRARIES})
CMakeSettings.json
{
"configurations": [
{
"name": "x86-Debug",
"generator": "Visual Studio 15 2017",
"configurationType": "Debug",
"buildRoot": "${env.USERPROFILE}\CMakeBuilds\${workspaceHash}\build\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-m -v:minimal",
"variables": [
{
"name": "CMAKE_TOOLCHAIN_FILE",
"value": "C:\github.com\vcpkg\scripts\buildsystems\vcpkg.cmake"
}
]
}
]
}
链接出错:
error LNK2019: unresolved external symbol "__declspec(dllimport) class boost::system::error_category const & __cdecl boost::system::system_category(void)" (__imp_?system_category@system@boost@@YAABVerror_category@12@XZ) referenced in function "public: __thiscall boost::system::error_code::error_code(void)" (??0error_code@system@boost@@QAE@XZ)
error LNK2019: unresolved external symbol "__declspec(dllimport) class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (__imp_?generic_category@system@boost@@YAABVerror_category@12@XZ) referenced in function "public: virtual bool __thiscall boost::system::error_category::std_category::equivalent(class std::error_code const &,int)const " (?equivalent@std_category@error_category@system@boost@@UBE_NABVerror_code@std@@H@Z)
error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall boost::gregorian::greg_month::greg_month(unsigned short)" (__imp_??0greg_month@gregorian@boost@@QAE@G@Z) referenced in function "public: __thiscall boost::gregorian::date::date(enum boost::date_time::special_values)" (??0date@gregorian@boost@@QAE@W4special_values@date_time@2@@Z)
error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall boost::gregorian::greg_month::operator unsigned short(void)const " (__imp_??Bgreg_month@gregorian@boost@@QBEGXZ) referenced in function "public: static unsigned int __cdecl boost::date_time::gregorian_calendar_base<struct boost::date_time::year_month_day_base<class boost::gregorian::greg_year,class boost::gregorian::greg_month,class boost::gregorian::greg_day>,unsigned int>::day_number(struct boost::date_time::year_month_day_base<class boost::gregorian::greg_year,class boost::gregorian::greg_month,class boost::gregorian::greg_day> const &)" (?day_number@?$gregorian_calendar_base@U?$year_month_day_base@Vgreg_year@gregorian@boost@@Vgreg_month@23@Vgreg_day@23@@date_time@boost@@I@date_time@boost@@SAIABU?$year_month_day_base@Vgreg_year@gregorian@boost@@Vgreg_month@23@Vgreg_day@23@@23@@Z)
fatal error LNK1120: 4 unresolved externals
Build failed
它是否给任何人敲响了警钟?我为此苦苦挣扎了几个小时。
您应该更改您的 cmake 文件以完全匹配 https://github.com/Microsoft/vcpkg/blob/master/ports/boost/usage。
例如在 find_package 中,包名应该是 Boost 而不是 boost,如果找不到 boost,添加 REQUIRED 会使它失败,cmake 可能找不到 boost 并默默地忽略它。
我正在尝试完成一项简单的任务,以检查在 Windows 中开发 "Linux apps" 有多容易。
我正在使用 vcpkg from Microsoft in order to setup headers and libs and crow ,一个使用 boost 作为驱动程序项目的 c++ http 服务器
来源简单
#include "crow.hpp"
int main()
{
crow::SimpleApp app;
CROW_ROUTE(app, "/")
([]() {
return "Hello world!";
});
app.port(18080).run();
}
我已经通过 vcpkg 下载了 boost 并使用 Visual Studio 对项目进行编码
cmake:
cmake_minimum_required (VERSION 3.8)
find_package(boost COMPONENTS filesystem system thread date_time REQUIRED)
message("this is ${Boost_INCLUDE_DIRS}")
include_directories ("C:\github.com\crow\include")
include_directories(SYSTEM PUBLIC ${Boost_INCLUDE_DIRS})
add_executable (engine "promo-engine-windows.cpp" "promo-engine-windows.h")
target_link_libraries(engine ${Boost_LIBRARIES})
CMakeSettings.json
{
"configurations": [
{
"name": "x86-Debug",
"generator": "Visual Studio 15 2017",
"configurationType": "Debug",
"buildRoot": "${env.USERPROFILE}\CMakeBuilds\${workspaceHash}\build\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-m -v:minimal",
"variables": [
{
"name": "CMAKE_TOOLCHAIN_FILE",
"value": "C:\github.com\vcpkg\scripts\buildsystems\vcpkg.cmake"
}
]
}
]
}
链接出错:
error LNK2019: unresolved external symbol "__declspec(dllimport) class boost::system::error_category const & __cdecl boost::system::system_category(void)" (__imp_?system_category@system@boost@@YAABVerror_category@12@XZ) referenced in function "public: __thiscall boost::system::error_code::error_code(void)" (??0error_code@system@boost@@QAE@XZ)
error LNK2019: unresolved external symbol "__declspec(dllimport) class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (__imp_?generic_category@system@boost@@YAABVerror_category@12@XZ) referenced in function "public: virtual bool __thiscall boost::system::error_category::std_category::equivalent(class std::error_code const &,int)const " (?equivalent@std_category@error_category@system@boost@@UBE_NABVerror_code@std@@H@Z)
error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall boost::gregorian::greg_month::greg_month(unsigned short)" (__imp_??0greg_month@gregorian@boost@@QAE@G@Z) referenced in function "public: __thiscall boost::gregorian::date::date(enum boost::date_time::special_values)" (??0date@gregorian@boost@@QAE@W4special_values@date_time@2@@Z)
error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall boost::gregorian::greg_month::operator unsigned short(void)const " (__imp_??Bgreg_month@gregorian@boost@@QBEGXZ) referenced in function "public: static unsigned int __cdecl boost::date_time::gregorian_calendar_base<struct boost::date_time::year_month_day_base<class boost::gregorian::greg_year,class boost::gregorian::greg_month,class boost::gregorian::greg_day>,unsigned int>::day_number(struct boost::date_time::year_month_day_base<class boost::gregorian::greg_year,class boost::gregorian::greg_month,class boost::gregorian::greg_day> const &)" (?day_number@?$gregorian_calendar_base@U?$year_month_day_base@Vgreg_year@gregorian@boost@@Vgreg_month@23@Vgreg_day@23@@date_time@boost@@I@date_time@boost@@SAIABU?$year_month_day_base@Vgreg_year@gregorian@boost@@Vgreg_month@23@Vgreg_day@23@@23@@Z)
fatal error LNK1120: 4 unresolved externals
Build failed
它是否给任何人敲响了警钟?我为此苦苦挣扎了几个小时。
您应该更改您的 cmake 文件以完全匹配 https://github.com/Microsoft/vcpkg/blob/master/ports/boost/usage。
例如在 find_package 中,包名应该是 Boost 而不是 boost,如果找不到 boost,添加 REQUIRED 会使它失败,cmake 可能找不到 boost 并默默地忽略它。