【问题标题】:Xcode 5.1.1 and BoostXcode 5.1.1 和 Boost
【发布时间】:2014-06-20 18:54:27
【问题描述】:

通过将 .dylib 文件 (boost) 添加到项目中解决了问题。

我正在尝试通过 Homebrew 将 Boost 1.55 连接到 Xcode 5。 Brew 按应有的方式安装了它。在 /usr/local/include && /usr/local/lib 中出现了 Boost 头文件和库的别名。

Xcode“搜索路径”设置: http://i.imgur.com/j5GJ0sh.png http://i.imgur.com/DXRxiyA.png

但是当我尝试编译简单的例子时:

#include <cstdlib>
#include <iostream>
#include <cstring>
#include <boost/regex.hpp>

using namespace std;
using namespace boost;

    int main()
    {
        const regex expression( "How to re" );

        string string1 = "How to re";

        bool match=regex_match(string1,expression);

        if (match){
            cout<<"Yes"<<endl;
        }

        return 0;
    }

错误:

架构 x86_64 的未定义符号:“boost::basic_regex >

::do_assign(char const*, char const*, unsigned int)”,引用自: boost::basic_regex > >::assign(char const*, char const*, unsigned int) in main.o "boost::re_detail::get_mem_block()", 参考自: boost::re_detail::perl_matcher, std::__1::allocator > >, boost::regex_traits > ::extend_stack() 在 main.o boost::re_detail::save_state_init::save_state_init(boost::re_detail::saved_state**, boost::re_detail::saved_state**) 在 main.o
“boost::re_detail::put_mem_block(void*)”,引用自: boost::re_detail::save_state_init::~save_state_init() 在 main.o boost::re_detail::perl_matcher, std::__1::allocator > >, boost::regex_traits > ::unwind_extra_block(bool) in main.o "boost::re_detail::verify_options(unsigned int, boost::regex_constants::_match_flags)”,引用自: boost::re_detail::perl_matcher, std::__1::allocator > >, boost::regex_traits > ::match_imp() in main.o "boost::re_detail::raise_runtime_error(std::runtime_error const&)", 参考自: 无效提升::re_detail::raise_error >> (boost::regex_traits_wrapper > > const&, boost::regex_constants::error_type) 在 main.o
“boost::re_detail::get_default_error_string(boost::regex_constants::error_type)”, 参考自: boost::re_detail::cpp_regex_traits_implementation::error_string(boost::regex_constants::error_type) main.o 中的 const
“boost::re_detail::cpp_regex_traits_implementation::transform_primary(char const*, char const*) const”,引用自: boost::cpp_regex_traits::transform_primary(char const*, char const*) const in main.o
“提升::re_detail::cpp_regex_traits_implementation::transform(char const*, char const*) const",引用自: boost::cpp_regex_traits::transform(char const*, char const*) const in main.o ld: 未找到架构的符号 x86_64 clang:错误:链接器命令失败,退出代码为 1(使用 -v 到 见调用)

真的很累,所以,请寻求您的帮助。

谢谢, - 菲利普

【问题讨论】:

  • 我没有在屏幕截图中看到它,但你是在 boost 中使用 -l 链接还是在 Xcode 中手动链接?
  • 没有。你能告诉我,我该怎么做?
  • 我不知道自制软件使用什么选项来构建提升,但请参阅boost.org/doc/libs/1_55_0/more/getting_started/… 以获得更多帮助。如果您发布 /usr/local/lib 的内容也会有所帮助。
  • pastebin.com/RiXmwHGP 所有这些文件——别名。在我添加了 boost 库的 .dylib 文件后,它就开始工作了。但是,据我所知,通过 brew 安装,我不应该将任何文件添加到项目中。

标签: c++ boost


【解决方案1】:

您有几个选项,但所有选项都涉及将库 libboost_regex 添加到您的项目以解决链接错误。即使您使用自制软件安装了 boost,您仍然需要将该库添加到您的项目中,因为 boost 的正则表达式代码包含已编译的部分。如果您不添加库,则链接器无法解析符号。

第一个选项是将/usr/local/lib 添加到库搜索路径,并将-lboost_regex 添加到其他链接器标志。如果您选择此选项,您可能还需要将 /usr/local/lib 添加到 Runpath Search Paths。此方法将链接到/usr/local/lib 中的动态库。

如果您希望您的程序是独立的,您可以链接到 boost_regex 的静态 (.a) 版本。为此,请在 Build Settings - Link Binary With Libraries 中将 libboost_regex.a 添加到您的项目中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-12
    • 2014-08-26
    • 2014-09-22
    • 1970-01-01
    相关资源
    最近更新 更多