尝试在某些代码上运行一些正则表达式,但代码不能使用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)
答案 0 :(得分:0)
这是一个连锁错误。请验证以下两件事:
Boost库中的一些库需要编译 -
其中&#34;正则表达式&#34;图书馆。特别是,链接器需要将与正则表达式相关的代码与两个Boost库链接起来 - boost_system
和boost_regex
。确保它们已经建成。
告诉链接器关于这些库的方法完全是
NetBeans职责 - 因此您需要配置项目
NetBeans以这种方式,它将传递有关的信息
库名称和链接器的位置。我习惯在我自己的Makefile中做到这一点,但还有其他方法可以做到这一点。您可以在NetBeans自己的帮助子系统中找到如何执行此操作的说明 - 只需查找C/C++ Project Properties Dialog Box: Linker
页面即可。因此,请确保您已将NetBeans项目配置为访问Boost库。
您可以找到更多信息here。