VS2022搭建Oat++项目遇LNK2019/LNK1120链接错误求助
Oat++项目在VS2022中构建出现LNK2019未解析外部符号错误
问题详情
用Visual Studio 2022跟着Oat官方文档搭第一个项目,代码没语法错误,但构建时弹出13个LNK2019未解析外部符号错误,最后触发fatal error LNK1120导致构建失败。试过常见的Oat配置方案,没用。
项目代码
#include "oatpp/web/server/HttpConnectionHandler.hpp" #include "oatpp/network/Server.hpp" #include "oatpp/network/tcp/server/ConnectionProvider.hpp" #include <iostream> using namespace oatpp; using namespace oatpp::base; using namespace oatpp::network; using namespace oatpp::network::tcp; using namespace oatpp::web; using namespace oatpp::web::server; void run() { /* Create Router for HTTP requests routing */ auto router = HttpRouter::createShared(); /* Create HTTP connection handler with router */ auto connectionHandler = HttpConnectionHandler::createShared(router); /* Create TCP connection provider */ auto connectionProvider = tcp::server::ConnectionProvider::createShared({"localhost", 8000, Address::IP_4}); /* Create server which takes provided TCP connections and passes them to HTTP connection handler */ Server server(connectionProvider, connectionHandler); /* Print info about server port */ OATPP_LOGI("MyAPP", "Server running on port %s", connectionProvider->getProperty("port").getData()); /* Run server */ server.run(); } int main(){ /* Init oatpp Environment */ Environment::init(); /* Run App */ run(); /* Destroy oatpp Environment */ Environment::destroy(); return 0; }
构建日志
Build started... 1>------ Build started: Project: OatWebApp01, Configuration: Debug x64 ------ 1>OatWebApp01.obj : error LNK2019: unresolved external symbol "public: static void __cdecl oatpp::base::Environment::init(void)" (?init@Environment@base@oatpp@@SAXXZ) referenced in function main 1>OatWebApp01.obj : error LNK2019: unresolved external symbol "public: static void __cdecl oatpp::base::Environment::destroy(void)" (?destroy@Environment@base@oatpp@@SAXXZ) referenced in function main 1>OatWebApp01.obj : error LNK2019: unresolved external symbol "public: static void __cdecl oatpp::base::Environment::logFormatted(unsigned int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,char const *,...)" (?logFormatted@Environment@base@oatpp@@SAXIAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEBDZZ) referenced in function "void __cdecl run(void)" (?run@@YAXXZ) 1>OatWebApp01.obj : error LNK2019: unresolved external symbol "public: static class oatpp::data::mapping::type::Type * __cdecl oatpp::data::mapping::type::__class::String::getType(void)" (?getType@String@__class@type@mapping@data@oatpp@@SAPEAVType@3456@XZ) referenced in function "public: __cdecl oatpp::data::mapping::type::ObjectWrapper<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class oatpp::data::mapping::type::__class::String>::ObjectWrapper<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class oatpp::data::mapping::type::__class::String>(class std::shared_ptr<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > const &)" (??0?$ObjectWrapper@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@VString@__class@type@mapping@data@oatpp@@@type@mapping@data@oatpp@@QEAA@AEBV?$shared_ptr@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@std@@@Z) 1>OatWebApp01.obj : error LNK2019: unresolved external symbol "public: static __int64 __cdecl oatpp::utils::String::compareCI_ASCII(void const *,__int64,void const *,__int64)" (?compareCI_ASCII@String@utils@oatpp@@SA_JPEBX_J01@Z) referenced in function "public: bool __cdecl oatpp::data::share::StringKeyLabelCI::operator==(class oatpp::data::share::StringKeyLabelCI const &)const " (??8StringKeyLabelCI@share@data@oatpp@@QEBA_NAEBV0123@@Z) 1>OatWebApp01.obj : error LNK2019: unresolved external symbol "public: __cdecl oatpp::data::share::StringKeyLabelCI::StringKeyLabelCI(class oatpp::data::mapping::type::String const &)" (??0StringKeyLabelCI@share@data@oatpp@@QEAA@AEBVString@type@mapping@23@@Z) referenced in function "public: class oatpp::data::share::StringKeyLabel __cdecl oatpp::provider::Provider<class oatpp::data::stream::IOStream>::getProperty(class oatpp::data::mapping::type::String const &)const " (?getProperty@?$Provider@VIOStream@stream@data@oatpp@@@provider@oatpp@@QEBA?AVStringKeyLabel@share@data@3@AEBVString@type@mapping@63@@Z) 1>OatWebApp01.obj : error LNK2019: unresolved external symbol "public: static class std::shared_ptr<class oatpp::web::server::HttpRouter> __cdecl oatpp::web::server::HttpRouter::createShared(void)" (?createShared@HttpRouter@server@web@oatpp@@SA?AV?$shared_ptr@VHttpRouter@server@web@oatpp@@@std@@XZ) referenced in function "void __cdecl run(void)" (?run@@YAXXZ) 1>OatWebApp01.obj : error LNK2019: unresolved external symbol "public: static class std::shared_ptr<class oatpp::web::server::HttpConnectionHandler> __cdecl oatpp::web::server::HttpConnectionHandler::createShared(class std::shared_ptr<class oatpp::web::server::HttpRouter> const &)" (?createShared@HttpConnectionHandler@server@web@oatpp@@SA?AV?$shared_ptr@VHttpConnectionHandler@server@web@oatpp@@@std@@AEBV?$shared_ptr@VHttpRouter@server@web@oatpp@@@6@@Z) referenced in function "void __cdecl run(void)" (?run@@YAXXZ) 1>OatWebApp01.obj : error LNK2019: unresolved external symbol "public: __cdecl oatpp::network::Server::Server(class std::shared_ptr<class oatpp::network::ConnectionProvider> const &,class std::shared_ptr<class oatpp::network::ConnectionHandler> const &)" (??0Server@network@oatpp@@QEAA@AEBV?$shared_ptr@VConnectionProvider@network@oatpp@@@std@@AEBV?$shared_ptr@VConnectionHandler@network@oatpp@@@4@@Z) referenced in function "void __cdecl run(void)" (?run@@YAXXZ) 1>OatWebApp01.obj : error LNK2019: unresolved external symbol "public: virtual __cdecl oatpp::network::Server::~Server(void)" (??1Server@network@oatpp@@UEAA@XZ) referenced in function "void __cdecl run(void)" (?run@@YAXXZ) 1>OatWebApp01.obj : error LNK2019: unresolved external symbol "public: void __cdecl oatpp::network::Server::run(class std::function<bool __cdecl(void)>)" (?run@Server@network@oatpp@@QEAAXV?$function@$$A6A_NXZ@std@@@Z) referenced in function "void __cdecl run(void)" (?run@@YAXXZ) 1>OatWebApp01.obj : error LNK2019: unresolved external symbol "public: __cdecl oatpp::network::Address::Address(class oatpp::data::mapping::type::String const &,unsigned short,enum oatpp::network::Address::Family)" (??0Address@network@oatpp@@QEAA@AEBVString@type@mapping@data@2@GW4Family@012@@Z) referenced in function "void __cdecl run(void)" (?run@@YAXXZ) 1>OatWebApp01.obj : error LNK2019: unresolved external symbol "public: __cdecl oatpp::network::tcp::server::ConnectionProvider::ConnectionProvider(class oatpp::network::Address const &,bool)" (??0ConnectionProvider@server@tcp@network@oatpp@@QEAA@AEBVAddress@34@_N@Z) referenced in function "void __cdecl std::_Construct_in_place<class oatpp::network::tcp::server::ConnectionProvider,class oatpp::network::Address const &,bool &>(class oatpp::network::tcp::server::ConnectionProvider &,class oatpp::network::Address const &,bool &)" (??$_Construct_in_place@VConnectionProvider@server@tcp@network@oatpp@@AEBVAddress@45@AEA_N@std@@YAXAEAVConnectionProvider@server@tcp@network@oatpp@@AEBVAddress@45@AEA_N@Z) 1>E:\H1LL4RY\Projects\cpp\OatPP\Learn\OatWebApp01\x64\Debug\OatWebApp01.exe : fatal error LNK1120: 13 unresolved externals 1>Done building project "OatWebApp01.vcxproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== ========== Build started at 18:17 and took 00.992 seconds ==========
解决方案
这些错误本质是链接器找不到Oat++库的实现文件,按以下步骤排查修复:
- 确认Oat++库已正确编译:从Oat++仓库拉取代码后,用VS2022打开其CMake项目,编译对应配置(Debug/Release、x64/x86),确保生成
oatpp.lib(Debug版可能是oatppd.lib)等库文件,检查编译输出目录确认文件存在。 - 配置附加库目录:右键项目→属性→链接器→常规→附加库目录,添加Oat++编译生成的库文件所在路径,注意匹配Debug/Release和平台架构。
- 添加附加依赖项:右键项目→属性→链接器→输入→附加依赖项,添加
oatpp.lib(Debug版加oatppd.lib),如果用到oatpp-network模块,还要加oatpp-network.lib/oatpp-networkd.lib。 - 检查头文件目录:右键项目→属性→C/C→常规→附加包含目录,确保Oat的
include目录已正确添加,避免头文件引用路径错误。 - 统一运行时库:Oat库编译时的运行时库设置(MD/MT类)要和你的项目一致,右键项目→属性→C/C→代码生成→运行时库,选择和Oat++编译时相同的选项(Debug通常选MDd或MTd,Release选MD或MT)。
- 用Oat++模板生成项目:如果是手动创建项目而非用Oat的CMake模板,建议直接用Oat提供的
starter-project模板,通过CMake生成VS项目,避免手动配置出错。
内容的提问来源于stack exchange,提问作者Hillary
相关产品推荐
相关产品推荐

