我想在Ubuntu 12.04(gcc 4.8.2)上使用boost_regex。我不能建立boost_regex代碼,因爲鏈接erros
我已經安裝了這樣的提升。
$ sudo apt-get install libboost-all-dev
而且我已經確認安裝了boost_regex庫。
$ ls /usr/lib/x86_64-linux-gnu | grep regex
libboost_regex.a
libboost_regex.so
libboost_regex.so.1.54.0
然後,我試圖建立一個正則表達式程序代碼。但我面臨鏈接錯誤。那麼我應該添加鏈接庫?
#include <boost/regex.hpp>
#include <iostream>
#include <string>
int main()
{
std::string line;
boost::regex pat("^Subject: (Re: |Aw:)*(.*)");
while (std::cin)
{
std::getline(std::cin, line);
boost::smatch matches;
if (boost::regex_match(line, matches, pat))
std::cout << matches[2] << std::endl;
}
}
$ g++ -Wall -std=c++11 -o out test2.cc -lboost_regex
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libboost_regex.so: undefined reference to `icu_52::Locale::~Locale()'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libboost_regex.so: undefined reference to `u_charType_52'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libboost_regex.so: undefined reference to `icu_52::Locale::Locale(icu_52::Locale const&)'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libboost_regex.so: undefined reference to `u_digit_52'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libboost_regex.so: undefined reference to `icu_52::Collator::createInstance(icu_52::Locale const&, UErrorCode&)'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libboost_regex.so: undefined reference to `icu_52::Locale::Locale()'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libboost_regex.so: undefined reference to `u_charFromName_52'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libboost_regex.so: undefined reference to `u_tolower_52'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libboost_regex.so: undefined reference to `u_isspace_52'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libboost_regex.so: undefined reference to `u_isblank_52'
collect2: error: ld returned 1 exit status
sehe你總是驚奇:-)我跟着我的Gentoo系統類似的步驟,讓我的提振高興。在我的情況下,我碰到了我的盒子而沒有重建提升,並且提升沒有找到libicu,因爲當我轉移到v58時它正在尋找v57。重建提升,固定。謝謝你另一個有用的答案。 – moodboom