【问题标题】:linking to boost regex in gcc链接到 gcc 中的增强正则表达式
【发布时间】:2010-10-08 05:37:01
【问题描述】:

我正在尝试编译我在 linux 上使用正则表达式的程序。我在 库/正则表达式/构建 通过键入 制作-fgcc.mak 它创建了一个目录 gcc,其中包含以下四个文件

boost_regex-gcc-1_35
boost_regex-gcc-d-1_35
libboost_regex-gcc-1_35.a
libboost_regex-gcc-d-1_35.a

现在我想使用我的程序中的正则表达式,它位于某个任意目录中。 我#included boost/regex.hpp

我收到错误消息,指出找不到 regex.hpp。然后我在 g++ 编译器中给出了 -I 选项。我没有得到那个错误。 但是我收到以下错误

undefined reference to `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)'

我搜索了一下,发现我需要以某种方式将上述 4 个库之一链接到我的程序。我该怎么做。我应该链接哪一个,为什么?

【问题讨论】:

    标签: c++ regex boost linker boost-regex


    【解决方案1】:

    在链接步骤中将libboost_regex-gcc-1_35.a 添加到您的目标文件列表中,或者将-static -lboost_regex-gcc-1_35 添加到相同的列表中。还要确保在编译步骤中有一个 -I 开关指向你的 boost 包含目录。如果库位于典型搜索路径之外(*nix 上的/usr/lib),将该目录添加到链接命令中,使用-Wl,-L/path/to/boost/libs 表示g++ 或简单地使用-L/path/to/boost/libsld 上。

    【讨论】:

      【解决方案2】:

      我在使用 boost 文件系统时也遇到了类似的问题。这是我需要做的让它静态链接。

      摘自我的原始(有问题的)Makefile: LIBS = -static -lboost_filesystem

      解决方案: LIBS = -Wl,-Bstatic -lboost_filesystem -lboost_system -Wl,-Bdynamic

      您可以从以下位置查看完整的 Makefile http://code.google.com/p/neptuner/source/browse/codebase/trunk/stratego/uboat/Makefile

      需要添加 boost_system 以使其正确链接。直接添加/指定 libboost*.a 会产生更多问题。注意 -Bdynamic 的存在是为了防止标准库的静态链接。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-10-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-12
        相关资源
        最近更新 更多