提升正则表达式链接:找不到库

Gra*_*ham 5 c++ regex linker boost

我在连接Boost Regex时遇到问题,尽管我可以运行(编译/链接)其他Boost程序.

我意识到这是"记录良好"但我找不到答案,因为各个帖子使用不同版本的Boost,不同的编译器,使用bjam(我使用过b2),似乎暗示我已经尝试过的等等.

安装程序

  • Visual Studio 10(我使用的是C++)

  • 提升版本:1.53.0

  • 初始安装:我遵循了如何在Visual Studio 2010中使用Boost(我一直到第二点4).我没有下载ICU对Regex的支持,因为我认为只有在需要Unicode支持时才需要这样做?

  • 我通过更新"包含目录"并添加C来将相关库包含在项目属性中:.......\Boost\boost_1_53_0

  • 我通过添加"C:.....\Boost\boost_1_53_0\stage\lib"将相关目录包含在项目属性库目录中,以便它知道库的链接位置(至少这是我的想法)这样做).

问题

我可以使用(例如)Boost随机数编译,链接和运行程序.

如果我试图添加正则表达式功能,请说:

boost::algorithm::split_regex( result, str, regex( "[0-9]+|->" ) )
Run Code Online (Sandbox Code Playgroud)

我得到以下形式的链接错误.

1>Bibtex.obj : error LNK2001: unresolved external symbol "private: class boost::basic_regex<char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > > & __thiscall boost::basic_regex<char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >::do_assign(char const *,char const *,unsigned int)" (?do_assign@?$basic_regex@DU?$regex_traits@DV?$w32_regex_traits@D@boost@@@boost@@@boost@@AAEAAV12@PBD0I@Z)
1>Bibtex.obj : error LNK2001: unresolved external symbol "public: bool __thiscall boost::re_detail::perl_matcher<class std::_String_const_iterator<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<struct boost::sub_match<class std::_String_const_iterator<char,struct std::char_traits<char>,class std::allocator<char> > > >,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >::find(void)" (?find@?$perl_matcher@V?$_String_const_iterator@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@U?$sub_match@V?$_String_const_iterator@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@boost@@@2@U?$regex_traits@DV?$w32_regex_traits@D@boost@@@boost@@@re_detail@boost@@QAE_NXZ)
1>Bibtex.obj : error LNK2001: unresolved external symbol "private: void __thiscall boost::re_detail::perl_matcher<class std::_String_const_iterator<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<struct boost::sub_match<class std::_String_const_iterator<char,struct std::char_traits<char>,class std::allocator<char> > > >,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >::construct_init(class boost::basic_regex<char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > > const &,enum boost::regex_constants::_match_flags)" (?construct_init@?$perl_matcher@V?$_String_const_iterator@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@U?$sub_match@V?$_String_const_iterator@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@boost@@@2@U?$regex_traits@DV?$w32_regex_traits@D@boost@@@boost@@@re_detail@boost@@AAEXABV?$basic_regex@DU?$regex_traits@DV?$w32_regex_traits@D@boost@@@boost@@@3@W4_match_flags@regex_constants@3@@Z)
1>C:\Users\kzzgrk\Dropbox\Projects\classes\Bibtex\BibtexFramework\Debug\BibtexFramework.exe : fatal error LNK1120: 3 unresolved externals
Run Code Online (Sandbox Code Playgroud)

我不知道如何解决这个问题,因为我似乎已经尝试了一切.我能想到的唯一可能性是我需要使用b2命令行程序构建boost库,但我无法找出应该推荐的内容(正如我上面提到的那样,很多引用都是bjam).

任何帮助/建议将不胜感激.

Tra*_*iny 0

我也遇到过同样的问题并修复了它。这种错误主要是由于你在XX.h文件中声明了函数但没有在XX.cpp文件中定义它(或者XX.cpp文件没有用)造成的

我的步骤: 1.下载boost

2.运行boost目录下的命令(需要先生成bjam.exe,参数根据你的电脑而定) bjam --with-regex --toolset=msvc-8.0 --stagedir="E:\download \boost_vc_80" 链接=静态运行时链接=静态运行时链接=共享线程=多调试版本

3.将libboost_regex-vc80-mt-1_55.lib复制到属性->链接->输入

再次构建您的项目,修复!

chnhu@telenav.cn