【发布时间】:2014-11-17 08:00:13
【问题描述】:
尝试在某些代码上运行一些正则表达式,但代码无法使用 boost 进行编译。当我安装 netbeans 和它的其余部分时,这个库是用 Cygwin 安装的,没有采取其他步骤。网上的说明不清楚还需要做什么,如果有的话,关于链接器,或者是否一切都应该开箱即用。
#include <iostream>
#include <string>
#include <boost/regex.hpp>
using namespace std;
bool regexValidate (string expr, string teststring)
{
boost::regex ex(expr);
if ( boost::regex_match (teststring,ex) ) {
cout << "true";
return true;
//} else if (regex_match (teststring,regex("^\s*\d*d\d*\s*$"))) {
// cout << "true";
// return true;
}
return false;
}
int main()
{
string diceexpr = "^\\s*\\d{1,}d\\d{1,}\\s*$";
string teststr = "10d10";
string teststr1 = "1d10";
string teststr2 = " 10d10 ";
cout << teststr << " is ";
if (regexValidate(diceexpr,teststr)) {
cout << " valid!" << endl;
} else {
cout << " invalid!" << endl;
}
cout << teststr1 << " is ";
if (regexValidate(diceexpr,teststr1)) {
cout << " valid!" << endl;
} else {
cout << " invalid!" << endl;
}
cout << teststr2 << " is ";
if (regexValidate(diceexpr,teststr2)) {
cout << " valid!" << endl;
} else {
cout << " invalid!" << endl;
}
return 0;
}
给定以下输出。
"/usr/bin/make" -f nbproject/Makefile-CIS17A.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/c/Users/[ ... redacted ... ]/Inclass Experiments'
"/usr/bin/make" -f nbproject/Makefile-CIS17A.mk dist/CIS17A/Cygwin_4.x-Windows/inclass_experiments.exe
make[2]: Entering directory '/cygdrive/c/Users/[ ... redacted ... ]/Inclass Experiments'
mkdir -p dist/CIS17A/Cygwin_4.x-Windows
g++ -std=c++11 -Wall -errors -Wextra -o dist/CIS17A/Cygwin_4.x-Windows/inclass_experiments build/CIS17A/Cygwin_4.x-Windows/main.o
/usr/lib/gcc/i686-pc-cygwin/4.8.3/../../../../i686-pc-cygwin/bin/ld: warning: cannot find entry symbol rrors; defaulting to 00401000
build/CIS17A/Cygwin_4.x-Windows/main.o: In function `regex_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char> >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char> > > >, char, boost::regex_traits<char> >':
/usr/include/boost/regex/v4/regex_match.hpp:50: undefined reference to `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::c_regex_traits<char> > >::match()'
build/CIS17A/Cygwin_4.x-Windows/main.o: In function `assign':
/usr/include/boost/regex/v4/basic_regex.hpp:382: undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::c_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'
build/CIS17A/Cygwin_4.x-Windows/main.o: In function `ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_14c_regex_traitsIcEEEEEC1ES6_S6_RNS_13match_resultsIS6_S9_EERKNS_11basic_regexIcSD_EENS_15regex_constants12_match_flagsES6_':
/usr/include/boost/regex/v4/perl_matcher.hpp:374: undefined reference to `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::c_regex_traits<char> > >::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::c_regex_traits<char> > > const&, boost::regex_constants::_match_flags)'
collect2: error: ld returned 1 exit status
nbproject/Makefile-CIS17A.mk:62: recipe for target 'dist/CIS17A/Cygwin_4.x-Windows/inclass_experiments.exe' failed
make[2]: *** [dist/CIS17A/Cygwin_4.x-Windows/inclass_experiments.exe] Error 1
make[2]: Leaving directory '/cygdrive/c/Users/[ ... redacted ... ]/Inclass Experiments'
nbproject/Makefile-CIS17A.mk:59: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/cygdrive/c/Users/[ ... redacted ... ]/Inclass Experiments'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 2s)
【问题讨论】: