【发布时间】:2013-10-13 11:55:26
【问题描述】:
我正在尝试在 Dev-C++ (tdm-gcc 4.7.1) 中使用 regex。
我已经从 boost.org 下载了 Boost 库并解压到
C:\Program Files (x86)\Dev-Cpp\boost
并在 Dev-C++ 中添加
C:\Program Files (x86)\Dev-Cpp\boost\libs
到图书馆。
包含路径 (C/C++):
C:\Program Files (x86)\Dev-Cpp\boost
main.cpp:
#include <boost/regex.hpp>
using namespace boost;
int main()
{
string s ("some txt PING :665454 some_text");
smatch mt;
regex r ("PING :(\\d+) "); // error
system( "pause" );
return 0;
}
错误:
D:\programowanie\dev-c++\main12\main.o main.cpp:(.text$_ZN5boost9re_detail27cpp_regex_traits_char_layerIcEC2ERKNS0_21cpp_regex_traits_baseIcEE[_ZN5boost9re_detail27cpp_regex_traits_char_layerIcEC2ERKNS0_21cpp_regex_traits_baseIcEE]+0xc3): undefined reference to `boost::re_detail::cpp_regex_traits_char_layer<char>::init()'
D:\programowanie\dev-c++\main12\main.o main.cpp:(.text$_ZN5boost9re_detail11raw_storage6extendEy[_ZN5boost9re_detail11raw_storage6extendEy]+0x60): undefined reference to `boost::re_detail::raw_storage::resize(unsigned long long)'
c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\bin\ld.exe main12/main.o: bad reloc address 0x60 in section `.text$_ZN5boost9re_detail11raw_storage6extendEy[_ZN5boost9re_detail11raw_storage6extendEy]'
c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\bin\ld.exe final link failed: Invalid operation
D:\programowanie\dev-c++\collect2.exe [Error] ld returned 1 exit status
【问题讨论】:
-
您需要链接到 boost 正则表达式,可能在 Dev-C++ 的编译器选项中(多年未使用 Dev-C++,抱歉)。可能搜索其他链接器选项并输入 -lboost_regex。
-
另外,如果您需要正则表达式,您可以使用新的 C++11 标准库中的新 regular expressions library 库。哦,不要使用
system("pause");。
标签: c++ windows gcc boost mingw