欢迎使用CSDN-markdown编辑器

来源:互联网 发布:程序员培训费用 编辑:程序博客网 时间:2024/06/06 09:43

VS2015下 boost log 无法链接(真正解决问题)

在VS2015下编译基于Boost log库的trivial例子时,编译器报出错误信息:

2>logtrivial_test1.obj : error LNK2019: 无法解析的外部符号 "public: static void __cdecl boost::log::v2s_mt_nt6::record_view::public_data::destroy(struct boost::log::v2s_mt_nt6::record_view::public_data const *)" (?destroy@public_data@record_view@v2s_mt_nt6@log@boost@@SAXPBU12345@@Z),该符号在函数 "public: void __thiscall boost::log::v2s_mt_nt6::record::reset(void)" (?reset@record@v2s_mt_nt6@log@boost@@QAEXXZ) 中被引用2>logtrivial_test1.obj : error LNK2019: 无法解析的外部符号 "public: bool __thiscall boost::log::v2s_mt_nt6::core::get_logging_enabled(void)const " (?get_logging_enabled@core@v2s_mt_nt6@log@boost@@QBE_NXZ),该符号在函数 "public: class boost::log::v2s_mt_nt6::record __thiscall boost::log::v2s_mt_nt6::sources::basic_composite_logger<char,class boost::log::v2s_mt_nt6::sources::severity_logger_mt<enum boost::log::v2s_mt_nt6::trivial::severity_level>,struct boost::log::v2s_mt_nt6::sources::multi_thread_model<class boost::log::v2s_mt_nt6::aux::light_rw_mutex>,struct boost::log::v2s_mt_nt6::sources::features<struct boost::log::v2s_mt_nt6::sources::severity<enum boost::log::v2s_mt_nt6::trivial::severity_level> > >::open_record<struct boost::parameter::aux::tagged_argument<struct boost::log::v2s_mt_nt6::keywords::tag::severity,enum boost::log::v2s_mt_nt6::trivial::severity_level const > >(struct boost::parameter::aux::tagged_argument<struct boost::log::v2s_mt_nt6::keywords::tag::severity,enum boost::log::v2s_mt_nt6::trivial::severity_level const > const &)" (??$open_record@U?$tagged_argument@Useverity@tag@keywords@v2s_mt_nt6@log@boost@@$$CBW4severity_level@trivial@456@@aux@parameter@boost@@@?$basic_composite_logger@DV?$severity_logger_mt@W4severity_level@trivial@v2s_mt_nt6@log@boost@@@sources@v2s_mt_nt6@log@boost@@U?$multi_thread_model@Vlight_rw_mutex@aux@v2s_mt_nt6@log@boost@@@2345@U?$features@U?$severity@W4severity_level@trivial@v2s_mt_nt6@log@boost@@@sources@v2s_mt_nt6@log@boost@@@1@@sources@v2s_mt_nt6@log@boost@@QAE?AVrecord@234@ABU?$tagged_argument@Useverity@tag@keywords@v2s_mt_nt6@log@boost@@$$CBW4severity_level@trivial@456@@aux@parameter@4@@Z) 中被引用2>logtrivial_test1.obj : error LNK2019: 无法解析的外部符号 "public: class boost::log::v2s_mt_nt6::record __thiscall boost::log::v2s_mt_nt6::core::open_record(class boost::log::v2s_mt_nt6::attribute_set const &)" (?open_record@core@v2s_mt_nt6@log@boost@@QAE?AVrecord@234@ABVattribute_set@234@@Z),该符号在函数 "protected: class boost::log::v2s_mt_nt6::record __thiscall boost::log::v2s_mt_nt6::sources::basic_logger<char,class boost::log::v2s_mt_nt6::sources::severity_logger_mt<enum boost::log::v2s_mt_nt6::trivial::severity_level>,struct boost::log::v2s_mt_nt6::sources::multi_thread_model<class boost::log::v2s_mt_nt6::aux::light_rw_mutex> >::open_record_unlocked<struct boost::parameter::aux::tagged_argument<struct boost::log::v2s_mt_nt6::keywords::tag::severity,enum boost::log::v2s_mt_nt6::trivial::severity_level const > >(struct boost::parameter::aux::tagged_argument<struct boost::log::v2s_mt_nt6::keywords::tag::severity,enum boost::log::v2s_mt_nt6::trivial::severity_level const > const &)" (??$open_record_unlocked@U?$tagged_argument@Useverity@tag@keywords@v2s_mt_nt6@log@boost@@$$CBW4severity_level@trivial@456@@aux@parameter@boost@@@?$basic_logger@DV?$severity_logger_mt@W4severity_level@trivial@v2s_mt_nt6@log@boost@@@sources@v2s_mt_nt6@log@boost@@U?$multi_thread_model@Vlight_rw_mutex@aux@v2s_mt_nt6@log@boost@@@4@@sources@v2s_mt_nt6@log@boost@@IAE?AVrecord@234@ABU?$tagged_argument@Useverity@tag@keywords@v2s_mt_nt6@log@boost@@$$CBW4severity_level@trivial@456@@aux@parameter@4@@Z) 中被引用......

网上搜的解决方案如下(通常不解决问题:-()

  • 修改boost/detail/winapi/config.hpp文件
  • 使BOOST_USE_WINAPI_VERSION的值大于BOOST_WINAPI_VERSION_WINXP
#if !defined(BOOST_USE_WINAPI_VERSION)#if defined(_WIN32_WINNT)//原代码为#define BOOST_USE_WINAPI_VERSION BOOST_WINAPI_VERSION_WINXP#define BOOST_USE_WINAPI_VERSION BOOST_WINAPI_VERSION_WIN7#elif defined(WINVER)#define BOOST_USE_WINAPI_VERSION WINVER#else......

经过实测的解决方案

经过试验,单单这样修改Boost头文件也不能真正解决问题。而且作为用户直接修改Boost库源代码不是个好主意

更正确的做法不是在变异log库的使用在bjam的命令行添加定义。相似命令行如下:

b2 define=BOOST_USE_WINAPI_VERSION=0x0601 threading=multi link=shared runtime-link=shared debug release

同时在用户自己的项目中也需要加上定义:

BOOST_USE_WINAPI_VERSION=0x0601

在VS2015上测试发现还是没有解决连接问题,通过研究Boost log自带例子程序的Jamfile.v2设置,发现还需要一个定义:

BOOST_ALL_DYN_LINK

在项目中加上这个定以后,问题得到了解决。

原创粉丝点击