【问题标题】:Unresolved external symbols with BoostBoost 无法解析的外部符号
【发布时间】:2016-05-17 17:05:00
【问题描述】:

我正在尝试从 Getting Started Guide 编译 Boost.Regex 程序,但即使我正在链接所需的库,我也会得到一些未解析的外部符号:

1>------ Build started: Project: Project1, Configuration: Debug Win32 ------
1>  main.cpp
1>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall boost::re_detail_106100::raw_storage::resize(unsigned int)" (?resize@raw_storage@re_detail_106100@boost@@QAEXI@Z) referenced in function "public: void * __thiscall boost::re_detail_106100::raw_storage::extend(unsigned int)" (?extend@raw_storage@re_detail_106100@boost@@QAEPAXI@Z)
1>main.obj : error LNK2019: unresolved external symbol "public: void * __thiscall boost::re_detail_106100::raw_storage::insert(unsigned int,unsigned int)" (?insert@raw_storage@re_detail_106100@boost@@QAEPAXII@Z) referenced in function "public: struct boost::re_detail_106100::re_syntax_base * __thiscall boost::re_detail_106100::basic_regex_creator<char,struct boost::regex_traits<char,class boost::cpp_regex_traits<char> > >::insert_state(int,enum boost::re_detail_106100::syntax_element_type,unsigned int)" (?insert_state@?$basic_regex_creator@DU?$regex_traits@DV?$cpp_regex_traits@D@boost@@@boost@@@re_detail_106100@boost@@QAEPAUre_syntax_base@23@HW4syntax_element_type@23@I@Z)
1>C:\Users\unknown\Documents\Visual Studio 2015\Projects\Project1\Debug\Project1.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

这是代码(取自here):

#include <boost/regex.hpp>
#include <iostream>
#include <string>

int main()
{
    std::string line;
    boost::regex pat("^Subject: (Re: |Aw: )*(.*)");

    while (std::cin)
    {
        std::getline(std::cin, line);
        boost::smatch matches;
        if (boost::regex_match(line, matches, pat))
            std::cout << matches[2] << std::endl;
    }
}

一些信息:

  • 这发生在调试和发布下
  • 我无法在 x64 下构建项目,因为库是 x86
  • 我使用bootstrap 构建静态库,然后使用b2
  • 我包含了libboost_regex-vc140-mt-1_61.liblibboost_regex-vc140-mt-gd-1_61.lib 用于调试)
  • 不使用 Unicode 字符集(在 Visual Studio 项目属性中)
  • 我正在使用 Visual Studio 2015
  • 我使用的是 Boost 1.61
  • 每个需要库的 Boost 代码都会发生这种情况
  • 这显然不会发生在仅标头的 Boost 库中

有什么想法吗?

【问题讨论】:

  • 此链接 lists.boost.org/boost-users/2010/04/57957.php 表明构建 boost 库和您的项目之间的编译器标志存在一些差异
  • @MirceaBaja 你不知道我有多高兴:) 非常感谢你,如果你愿意,把它作为答案发布,我会接受!

标签: c++ boost static-linking


【解决方案1】:

此链接http://lists.boost.org/boost-users/2010/04/57957.php 表明构建 boost 库和您的项目之间的编译器标志存在一些差异

【讨论】:

    猜你喜欢
    • 2018-07-01
    • 2018-01-16
    • 2018-02-21
    • 2014-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-09
    • 2011-03-21
    相关资源
    最近更新 更多