繁体   English   中英

使用G ++在Netbeans中无法编译Boost库

[英]Boost library not compiling in Netbeans with G++

试图在某些代码上运行某些正则表达式,但该代码无法通过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)

这是一个链接错误。 请验证以下两件事:

  • Boost库集中的某些库需要编译-其中包括“ regex”库。 特别是,链接器需要使用两个Boost库boost_systemboost_regex链接与正则表达式相关的代码。 确保它们已构建。

  • 告诉链接器这些库的方法完全是NetBeans的责任-因此,您需要以这种方式在NetBeans中配置项目,以便将有关库名称和位置的信息传递给链接器。 我曾经在自己的Makefile中执行此操作,但是也有其他方法可以执行此操作。 您可以在NetBeans自己的帮助子系统中找到如何执行此操作的描述-只需查找“ C/C++ Project Properties Dialog Box: Linker页面。 因此,请确保已将NetBeans项目配置为访问Boost库。

您可以在此处找到更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM