无法将Boost库链接到vs2010

时间:2015-04-23 18:01:25

标签: c++ visual-studio-2010 boost

我知道这个问题已在很多时候被问过了。但在尝试了所有提到的解决方案之后,我仍然无法编译Test Boost代码。

我已按照以下步骤进行安装: -

  1. 将Boost解压缩到一个新目录。
  2. 启动64位MSVC命令提示符并切换到解压缩Boost的目录。
  3. 运行:bootstrap
  4. 运行:b2 toolset = msvc-10.0 --build-type = complete --libdir = C:\ Boost \ lib \ x64 architecture = x86 address-model = 64 install
  5. 将C:\ Boost \ include \ boost-(版本)添加到Microsoft.Cpp.Win32.user属性表中的包含路径。
  6. 将C:\ Boost \ lib \ x64添加到Microsoft.Cpp.Win32.user属性表中的libs路径。
  7. 此外,我已在其他库目录中添加了lib路径。

    我正在尝试编译标准代码来测试boost是否正常工作。

    #include <iostream>
    #include <boost/shared_ptr.hpp>
    #include <boost/regex.hpp>
    
    using namespace std;
    
    struct Hello 
    {
        Hello(){ 
            cout << "Hello constructor" << endl;
        }
    
        ~Hello(){
            cout << "Hello destructor" << endl;
            cin.get();
        }
    };
    
    
    int main(int argc, char**argv)
    {
        //Boost regex, compiled library
        boost::regex regex("^(Hello|Bye) Boost$");
        boost::cmatch helloMatches;
        boost::regex_search("Hello Boost", helloMatches, regex);
        cout << "The word between () is: " << helloMatches[1] << endl;
    
        //Boost shared pointer, header only library
        boost::shared_ptr<Hello> sharedHello(new Hello);
    
        return 0;
    }
    

    我得到的链接器错误是: -

    1>Sample.obj : error LNK2019: 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) referenced in function "public: 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> > >::assign(char const *,char const *,unsigned int)" (?assign@?$basic_regex@DU?$regex_traits@DV?$w32_regex_traits@D@boost@@@boost@@@boost@@QAEAAV12@PBD0I@Z)
    1>Sample.obj : error LNK2019: unresolved external symbol "public: bool __thiscall boost::re_detail::perl_matcher<char const *,class std::allocator<struct boost::sub_match<char const *> >,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >::find(void)" (?find@?$perl_matcher@PBDV?$allocator@U?$sub_match@PBD@boost@@@std@@U?$regex_traits@DV?$w32_regex_traits@D@boost@@@boost@@@re_detail@boost@@QAE_NXZ) referenced in function "bool __cdecl boost::regex_search<char const *,class std::allocator<struct boost::sub_match<char const *> >,char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >(char const *,char const *,class boost::match_results<char const *,class std::allocator<struct boost::sub_match<char const *> > > &,class boost::basic_regex<char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > > const &,enum boost::regex_constants::_match_flags,char const *)" (??$regex_search@PBDV?$allocator@U?$sub_match@PBD@boost@@@std@@DU?$regex_traits@DV?$w32_regex_traits@D@boost@@@boost@@@boost@@YA_NPBD0AAV?$match_results@PBDV?$allocator@U?$sub_match@PBD@boost@@@std@@@0@ABV?$basic_regex@DU?$regex_traits@DV?$w32_regex_traits@D@boost@@@boost@@@0@W4_match_flags@regex_constants@0@0@Z)
    1>Sample.obj : error LNK2019: unresolved external symbol "private: void __thiscall boost::re_detail::perl_matcher<char const *,class std::allocator<struct boost::sub_match<char const *> >,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@PBDV?$allocator@U?$sub_match@PBD@boost@@@std@@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) referenced in function "public: __thiscall boost::re_detail::perl_matcher<char const *,class std::allocator<struct boost::sub_match<char const *> >,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >::perl_matcher<char const *,class std::allocator<struct boost::sub_match<char const *> >,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >(char const *,char const *,class boost::match_results<char const *,class std::allocator<struct boost::sub_match<char const *> > > &,class boost::basic_regex<char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > > const &,enum boost::regex_constants::_match_flags,char const *)" (??0?$perl_matcher@PBDV?$allocator@U?$sub_match@PBD@boost@@@std@@U?$regex_traits@DV?$w32_regex_traits@D@boost@@@boost@@@re_detail@boost@@QAE@PBD0AAV?$match_results@PBDV?$allocator@U?$sub_match@PBD@boost@@@std@@@2@ABV?$basic_regex@DU?$regex_traits@DV?$w32_regex_traits@D@boost@@@boost@@@2@W4_match_flags@regex_constants@2@0@Z)
    1>C:\Users\J.A.R.V.I.S\documents\visual studio 2010\Projects\Boost Sample\Debug\Boost Sample.exe : fatal error LNK1120: 3 unresolved externals
    1>
    

    我在这里缺少什么? 我正在使用VS2010和Windows 64位。

    由于

1 个答案:

答案 0 :(得分:0)

有2个问题导致链接器错误: -

  1. Properties-&gt; Linker-&gt; Input-&gt; AdditionalDependencies

  2. 中缺少其他链接器依赖项
  3. 项目是win32。需要使用配置管理器将其转换为x64。