链接到 gcc 中的增强正则表达式
我正在尝试编译我在 linux 上使用正则表达式的程序.我在库/正则表达式/构建通过键入制作-fgcc.mak它创建了一个目录 gcc,其中包含以下四个文件
i am trying to compile my program which uses regex on linux. I built the boost library in the libs/regex/build by typing make -fgcc.mak which created a directory gcc which contains the following four files
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
Now I want to use regex from my program which is in some arbitrary directory. I #included boost/regex.hpp
我收到错误消息,指出找不到 regex.hpp.然后我在 g++ 编译器中给出了 -I 选项.我没有得到那个错误.但我收到以下错误
I got the error which stated that regex.hpp is not found. Then I gave the -I option in the g++ compiler. I didn't get that error. But I get the following error
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 个库之一链接到我的程序.我该怎么做.我应该链接哪一个,为什么?
I googled and found that I need to somehow link one of the above 4 libraries to my program. How can I do it. Which one should I link and why?
推荐答案
在链接步骤中将 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/libs
在 ld
上.
Either add libboost_regex-gcc-1_35.a
to your list of object files in your link step or add -static -lboost_regex-gcc-1_35
to the same. Also be sure that you have an -I
switch pointing to your boost includes directory in your compile step. If the libraries are outside the typical search path (/usr/lib
on *nix), add that directory to your link command with -Wl,-L/path/to/boost/libs
for g++
or simply -L/path/to/boost/libs
on ld
.
相关文章