我正在与某人进行项目合作,我们有完全相同的代码,但是他的代码在我的继续抛出错误的同时仍在编译。这是我的代码:
bool r_parser::parseMake(string name, string command, string type, string val)
{
regex regName("^\\w+$");
if(std::regex_match(name, regName) == true)
{
cout << "We have a match!" << endl;
}
return false;
}
这是我得到的错误:
'undefined reference to std::basic_regex<char, std::regex_traits<char> >::_M_compile()'
'undefined reference to bool std::regex_match<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<std::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, char, std::regex_traits<char> >(__gnu_cxx::__normal_iterator<char const*, std::string>, __gnu_cxx::__normal_iterator<char const*, std::string>, std::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<std::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > >&, std::basic_regex<char, std::regex_traits<char> > const&, std::bitset<11u>)'
由于我的伙伴的代码已编译,而我们的代码找不到任何不同之处,所以我想知道是否有人可以阐明这种情况。
谢谢你的时间。
编辑:我忘了提及我有:
#include <regex>
#include <string>
#include <iostream>
using namespace std;
在我的头文件中。
我做了一些调查研究,迈克尔,并且它会出现#include <regex>
的只有一个占位符,直到GCC版本4.9.0。
如果您使用的是Windows系统(我似乎还记得您),那么您是通过MinGW使用GCC的,因此您需要手动更新到最新版本。我使用的是4.9.1,这就是为什么它对我有用。您可以从Sourceforge下载。
如果您使用的是Linux,则应该能够通过存储库更新gcc和g ++。
如果您不想更新,也可以使用Boost库。但是,我建议您更新编译器,主要是因为使用最新版本的编译器通常是一个好主意,除非您有明确的理由不这样做。
抱歉,我不能早点回答,但是希望对您有所帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句