2014-03-29 44 views
2

我想使用boost正則表達式庫,但我無法設法編譯我的程序。涉及類似錯誤消息的所有相關問題似乎與正則表達式庫沒有正確鏈接的情況有關。我認爲我在連接它,但也許我正在做一些愚蠢的事情......也許有人看到我的錯誤?
這裏是我的測試程序:如何包含/鏈接boost :: regex庫?

// ~/workspace/test/test.cpp 
#include <string> 
#include <iostream> 
#include <boost/regex.hpp> 
int main(){ 
    std::string s("abaab"); 
    boost::regex r("[ab]*"); 
    std::cout << boost::regex_match(s,r) << std::endl; 
} 

這裏有升壓二進制文件(我通過synaptic安裝他們的Xubuntu):

/usr/lib/i386-linux-gnu$ ls libboost_regex* -al 
    -rw-r--r-- 1 root root 2169582 Okt 13 05:14 libboost_regex.a 
    lrwxrwxrwx 1 root root  24 Okt 13 05:13 libboost_regex.so -> libboost_regex.so.1.53.0 
    -rw-r--r-- 1 root root 1002568 Okt 13 05:14 libboost_regex.so.1.53.0 

不過運行

時,我十分醜陋的錯誤信息
~/workspace/test$ g++ -L/usr/lib/i386-linux-gnu/ -lboost_regex test.cpp 

這裏是完整的信息:

~/workspace/test$ g++ -L/usr/lib/i386-linux-gnu/ -lboost_regex test.cpp 
    /tmp/cc1yDf0v.o: In function `bool boost::regex_match<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >(__gnu_cxx::__normal_iterator<char const*, std::string>, __gnu_cxx::__normal_iterator<char const*, std::string>, boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > >&, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)': 
    test.cpp:(.text._ZN5boost11regex_matchIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS5_EEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEbT_SD_RNS_13match_resultsISD_T0_EERKNS_11basic_regexIT1_T2_EENS_15regex_constants12_match_flagsE[_ZN5boost11regex_matchIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS5_EEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEbT_SD_RNS_13match_resultsISD_T0_EERKNS_11basic_regexIT1_T2_EENS_15regex_constants12_match_flagsE]+0x4c): 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::cpp_regex_traits<char> > >::match()' 
    /tmp/cc1yDf0v.o: In function `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::assign(char const*, char const*, unsigned int)': 
    test.cpp:(.text._ZN5boost11basic_regexIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE6assignEPKcS7_j[_ZN5boost11basic_regexIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE6assignEPKcS7_j]+0x22): undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)' 
    /tmp/cc1yDf0v.o: In function `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::cpp_regex_traits<char> > >::perl_matcher(__gnu_cxx::__normal_iterator<char const*, std::string>, __gnu_cxx::__normal_iterator<char const*, std::string>, boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > >&, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags, __gnu_cxx::__normal_iterator<char const*, std::string>)': 
    test.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEC2ES6_S6_RNS_13match_resultsIS6_S9_EERKNS_11basic_regexIcSD_EENS_15regex_constants12_match_flagsES6_[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEC5ES6_S6_RNS_13match_resultsIS6_S9_EERKNS_11basic_regexIcSD_EENS_15regex_constants12_match_flagsES6_]+0xcd): 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::cpp_regex_traits<char> > >::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)' 
    collect2: error: ld returned 1 exit status 

標題似乎被發現,對吧?海灣合作委員會如何知道boost::re_detail::perl_matcherboost::basic_regex
我不知道問題可能是什麼。也許這是鏈接畢竟? 在此先感謝!

+0

如果您已經通過使用'sudo apt-get install libboost-all-dev'安裝了libboost-all-dev, ,試着在沒有'-L'選項的情況下編譯它。 – jfly

+0

感謝您的提示,但是使用'g ++ -lboost_regex test.cpp'進行編譯並不會改變任何內容 - 同樣的錯誤,但是這表明我的'-L'選項 – Leolo

+0

刪除你的-L路徑上的斜線 – holtavolt

回答