在 Ubuntu 上链接 TR1?
我已经使用 std::tr1::regex 编写了一个类,但我不知道如何链接它。我得到(对不起,大转储......):
$ g++ DictReader.cpp -std=c++0x
/usr/include/c++/4.4/tr1_impl/regex:2255: warning: inline function ‘bool std::tr1::regex_search(_Bi_iter, _Bi_iter, std::tr1::match_results<_Bi_iter, _Allocator>&, const std::tr1::basic_regex<_Ch_type, _Rx_traits>&, std::tr1::regex_constants::match_flag_type) [with _Bi_iter = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Allocator = std::allocator<std::tr1::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, _Ch_type = char, _Rx_traits = std::tr1::regex_traits<char>]’ used but never defined
/usr/lib/gcc/x86_64-linux-gnu/4.4.1/../../../../lib/crt1.o: In function `_start':
/build/buildd/eglibc-2.10.1/csu/../sysdeps/x86_64/elf/start.S:109: undefined reference to `main'
/tmp/ccgBkWlK.o: In function `DictReader::operator++(int)':
DictReader.cpp:(.text+0xb2a): undefined reference to `bool std::tr1::regex_search<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::tr1::sub_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, char, std::tr1::regex_traits<char> >(__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::tr1::match_results<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::tr1::sub_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >&, std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&, std::bitset<11ul>)'
/tmp/ccgBkWlK.o: In function `std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::basic_regex(char const*, unsigned int)':
DictReader.cpp:(.text._ZNSt3tr111basic_regexIcNS_12regex_traitsIcEEEC1EPKcj[std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::basic_regex(char const*, unsigned int)]+0x75): undefined reference to `std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::_M_compile()'
/tmp/ccgBkWlK.o: In function `std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::basic_regex(std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&)':
DictReader.cpp:(.text._ZNSt3tr111basic_regexIcNS_12regex_traitsIcEEEC1ERKS3_[std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::basic_regex(std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&)]+0x60): undefined reference to `std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::_M_compile()'
collect2: ld returned 1 exit status.
我应该链接什么?
I have written a class using std::tr1::regex, and I don't know how to link it. I get (sorry for the large dump...) :
$ g++ DictReader.cpp -std=c++0x
/usr/include/c++/4.4/tr1_impl/regex:2255: warning: inline function ‘bool std::tr1::regex_search(_Bi_iter, _Bi_iter, std::tr1::match_results<_Bi_iter, _Allocator>&, const std::tr1::basic_regex<_Ch_type, _Rx_traits>&, std::tr1::regex_constants::match_flag_type) [with _Bi_iter = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Allocator = std::allocator<std::tr1::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, _Ch_type = char, _Rx_traits = std::tr1::regex_traits<char>]’ used but never defined
/usr/lib/gcc/x86_64-linux-gnu/4.4.1/../../../../lib/crt1.o: In function `_start':
/build/buildd/eglibc-2.10.1/csu/../sysdeps/x86_64/elf/start.S:109: undefined reference to `main'
/tmp/ccgBkWlK.o: In function `DictReader::operator++(int)':
DictReader.cpp:(.text+0xb2a): undefined reference to `bool std::tr1::regex_search<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::tr1::sub_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, char, std::tr1::regex_traits<char> >(__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::tr1::match_results<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::tr1::sub_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >&, std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&, std::bitset<11ul>)'
/tmp/ccgBkWlK.o: In function `std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::basic_regex(char const*, unsigned int)':
DictReader.cpp:(.text._ZNSt3tr111basic_regexIcNS_12regex_traitsIcEEEC1EPKcj[std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::basic_regex(char const*, unsigned int)]+0x75): undefined reference to `std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::_M_compile()'
/tmp/ccgBkWlK.o: In function `std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::basic_regex(std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&)':
DictReader.cpp:(.text._ZNSt3tr111basic_regexIcNS_12regex_traitsIcEEEC1ERKS3_[std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::basic_regex(std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&)]+0x60): undefined reference to `std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::_M_compile()'
collect2: ld returned 1 exit status.
What should I link against?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个链接器错误,它没有找到您正在使用的函数。 TR1 仍然是新的,因此可能无法在所有地方实施。我建议您改用 boost 正则表达式库。
This is a linker error, it does not found the function you are using. TR1 is still new so it may not be implemented everywhere. I recommend you to use the boost regex library instead.