【问题标题】:Unable to link Boost libs to vs2010无法将 Boost 库链接到 vs2010
【发布时间】:2015-04-23 18:01:24
【问题描述】:

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

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

  1. 将 Boost 解压缩到新目录中。
  2. 启动 64 位 MSVC 命令提示符并切换到解压 Boost 的目录。
  3. 运行:引导
  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-(version) 添加到 Microsoft.Cpp.Win32.user 属性表中的包含路径。
  6. 将 C:\Boost\lib\x64 添加到 Microsoft.Cpp.Win32.user 属性表中的库路径。

另外,我在附加库目录中添加了 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 64bit。

谢谢

【问题讨论】:

  • 您是否告诉它链接到库?仅添加库 path 是不够的。
  • @CaptainObvlious 我该怎么做。
  • 将他们添加到Properties-&gt;Linker-&gt;Input-&gt;AdditionalDependencies

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


【解决方案1】:

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

  1. Properties->Linker->Input->AdditionalDependencies 中没有其他链接器依赖项

  2. 项目是 win32。需要使用配置管理器将其转换为 x64。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-15
    • 1970-01-01
    • 1970-01-01
    • 2019-01-31
    • 2011-08-22
    • 1970-01-01
    • 2020-06-22
    • 1970-01-01
    相关资源
    最近更新 更多