链接器错误 - 未定义的符号

Posted

技术标签:

【中文标题】链接器错误 - 未定义的符号【英文标题】:Linker error - Undefined symbols 【发布时间】:2015-11-30 12:01:44 【问题描述】:

问候

我已经在VS2013 (1.2.0-rc3) 中下载并编译了log4cplus。编译很好(调试和发布)我尝试在我的代码中使用它,但我得到很多链接错误,我尝试过的任何事情都没有删除它们。我正在使用 log4cplus 项目中的相同包含,以及我编译的库,我仍然得到这些。

1>------ Build started: Project: MYPROJECT, Configuration: Debug Win32 ------
1>utility.cpp.obj : error LNK2001: unresolved external symbol "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)
1>utility.cpp.obj : error LNK2001: unresolved external symbol "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)
1>device.obj : error LNK2001: unresolved external symbol "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)
1>path_tree.obj : error LNK2001: unresolved external symbol "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)
1>cim_manager.obj : error LNK2001: unresolved external symbol "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)
1>pin_manager.obj : error LNK2001: unresolved external symbol "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)
1>nautilus.obj : error LNK2001: unresolved external symbol "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)
1>ravis.obj : error LNK2001: unresolved external symbol "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)
1>ncr.obj : error LNK2001: unresolved external symbol "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)
1>wincore.obj : error LNK2001: unresolved external symbol "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)
1>atm_utility.obj : error LNK2001: unresolved external symbol "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)
1>banqit.obj : error LNK2001: unresolved external symbol "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)
1>grg.obj : error LNK2001: unresolved external symbol "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)
1>king_teller.obj : error LNK2001: unresolved external symbol "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)
1>supervisor_manager.obj : error LNK2001: unresolved external symbol "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)
1>registry_manager.obj : error LNK2001: unresolved external symbol "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)
1>device_manager.obj : error LNK2001: unresolved external symbol "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)
1>atm_factory.obj : error LNK2001: unresolved external symbol "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)
1>database_manager.obj : error LNK2001: unresolved external symbol "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)
1>user_interface.obj : error LNK2001: unresolved external symbol "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)
1>fit_manager.obj : error LNK2001: unresolved external symbol "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)

我在这里缺少什么?!

提前致谢

【问题讨论】:

【参考方案1】:

找到问题了!!

我必须在我的项目CMakeLists.txt 中将/Zc:wchar_t 设置为set_target_properties

set_target_properties(MYPROJECT PROPERTIES COMPILE_FLAGS "/W2 /Zc:wchar_t")

【讨论】:

以上是关于链接器错误 - 未定义的符号的主要内容,如果未能解决你的问题,请参考以下文章

Apple Mach-O 链接器错误/架构 i386 的未定义符号:

链接器错误:ld:未找到架构 x86_64 的符号

Apple Mach-O 链接器错误 - 架构 x86_64 的未定义符号:“_UISceneWillEnterForegroundNotification”和“___isPlatformVersio

SWIG链接器:未定义的符号:_ZN2cv8fastFreeEPv(cv :: fastFree(void *))

神秘的链接器错误

SWIG 链接器:未定义符号:_ZN2cv8fastFreeEPv (cv::fastFree(void*))