basic_regex是一个未定义的符号 - Boost框架链接器错误

时间:2014-11-22 04:51:39

标签: c++ xcode boost osx-yosemite

我正在使用boost框架测试应用程序。要做到这一点,我已经跟着

github链接和构建框架并相应地插入。我设置项目属性如下

Language Dialect set to C++11 [-std=c++11]

C++ Standard Library set to libc++ (LLVM C++ standard library with C++11 support)

OS X deployment target 10.10

避免错误

我删除关键字寄存器 并更改了我的代码如下(请查找以下attrched代码的#pragma标记),但没有任何关于我的工作。删除register关键字后我没有得到弃用的警告。 但是无论有没有警告我都会遇到链接器错误。 请帮我解决这些错误。

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-register"

#pragma clang diagnostic pop

#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;
    }
}

after building boost my file stuture

错误日志

Undefined symbols for architecture x86_64:
  "boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)", referenced from:
      boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::assign(char const*, char const*, unsigned int) in main.o
  "boost::re_detail::get_mem_block()", referenced from:
      boost::re_detail::perl_matcher<std::__1::__wrap_iter<char const*>, std::__1::allocator<boost::sub_match<std::__1::__wrap_iter<char const*> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::extend_stack() in main.o
      boost::re_detail::save_state_init::save_state_init(boost::re_detail::saved_state**, boost::re_detail::saved_state**) in main.o
  "boost::re_detail::put_mem_block(void*)", referenced from:
      boost::re_detail::save_state_init::~save_state_init() in main.o
      boost::re_detail::perl_matcher<std::__1::__wrap_iter<char const*>, std::__1::allocator<boost::sub_match<std::__1::__wrap_iter<char const*> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::unwind_extra_block(bool) in main.o
  "boost::re_detail::verify_options(unsigned int, boost::regex_constants::_match_flags)", referenced from:
      boost::re_detail::perl_matcher<std::__1::__wrap_iter<char const*>, std::__1::allocator<boost::sub_match<std::__1::__wrap_iter<char const*> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::match_imp() in main.o
  "boost::re_detail::raise_runtime_error(std::runtime_error const&)", referenced from:
      void boost::re_detail::raise_error<boost::regex_traits_wrapper<boost::regex_traits<char, boost::cpp_regex_traits<char> > > >(boost::regex_traits_wrapper<boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::error_type) in main.o
  "boost::re_detail::get_default_error_string(boost::regex_constants::error_type)", referenced from:
      boost::re_detail::cpp_regex_traits_implementation<char>::error_string(boost::regex_constants::error_type) const in main.o
  "boost::re_detail::cpp_regex_traits_implementation<char>::transform_primary(char const*, char const*) const", referenced from:
      boost::cpp_regex_traits<char>::transform_primary(char const*, char const*) const in main.o
  "boost::re_detail::cpp_regex_traits_implementation<char>::transform(char const*, char const*) const", referenced from:
      boost::cpp_regex_traits<char>::transform(char const*, char const*) const in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

1 个答案:

答案 0 :(得分:2)

您需要将boost链接到项目中:

  1. 找到&#34;搜索路径&#34; Project Navigator中的部分。
  2. 将会有一个名为:&#34;图书馆搜索路径&#34;。
  3. 的小节
  4. 添加已安装的boost的lib目录,通常类似于:... / boost * / libs
  5. 请注意,在同一部分中,您应该在&#34;标题搜索路径&#34;

    下添加主要的boost目录

    修改 您可以在此处找到入门指南:http://www.boost.org/doc/libs/1_57_0/more/getting_started/unix-variants.html

    有趣的是,你会注意到default folder结构应该是:boost_1_57_0 / libs注意缺少任何&#34; i386&#34;或&#34; x86_64&#34;。因此,我非常关注您的升压设置。

    另请注意,boost::regexheader only file。我会在您的&#34;标题搜索路径&#34;中包含boost_1_57_0 / boost进行健全性检查。