3

I'm trying to use boost_regex on ubuntu 12.04 (gcc 4.8.2).

I've installed boost like this.

$ sudo apt-get install libboost-all-dev 

And I've confirmed boost_regex libraries are installed on.

$ ls /usr/lib/x86_64-linux-gnu | grep regex
libboost_regex.a
libboost_regex.so
libboost_regex.so.1.54.0

Then, I've tried to build a regex program code. But I faced link errors. Then what should I add link libraries?

 #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

2 Answers 2

3

Package libboost-dev-all depends on (using dpkg --status):

libboost-dev
libboost-tools-dev
libboost-atomic-dev
libboost-chrono-dev
libboost-context-dev
libboost-coroutine-dev
libboost-date-time-dev
libboost-exception-dev
libboost-filesystem-dev
libboost-graph-dev
libboost-graph-parallel-dev
libboost-iostreams-dev
libboost-locale-dev
libboost-log-dev
libboost-math-dev
libboost-mpi-dev
libboost-mpi-python-dev
libboost-program-options-dev
libboost-python-dev
libboost-random-dev
libboost-regex-dev
libboost-serialization-dev
libboost-signals-dev
libboost-system-dev
libboost-test-dev
libboost-thread-dev
libboost-timer-dev
libboost-wave-dev

As you can see, e.g. libboost-regex-dev doesn't contain the libraries:

$ dpkg --listfiles libboost-regex-dev 
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/libboost-regex-dev
/usr/share/doc/libboost-regex-dev/copyright
/usr/share/doc/libboost-regex-dev/changelog.gz

That's because libboost-regex-dev depends on libboost-regex1.54-dev:

$ dpkg --listfiles libboost-regex1.54-dev 
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/libboost-regex1.54-dev
/usr/share/doc/libboost-regex1.54-dev/copyright
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libboost_regex.a
/usr/share/doc/libboost-regex1.54-dev/changelog.Debian.gz
/usr/lib/x86_64-linux-gnu/libboost_regex.so

Ah! But it requires ICU:

$ ldd /usr/lib/x86_64-linux-gnu/libboost_regex.so
linux-vdso.so.1 =>  (0x00007ffc265fb000)
libicuuc.so.52 => /usr/lib/x86_64-linux-gnu/libicuuc.so.52 (0x00007feb20dc0000)
libicui18n.so.52 => /usr/lib/x86_64-linux-gnu/libicui18n.so.52 (0x00007feb209b9000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007feb2063d000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007feb20426000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007feb20208000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007feb1fe43000)
libicudata.so.52 => /usr/lib/x86_64-linux-gnu/libicudata.so.52 (0x00007feb1e5d6000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007feb1e3d2000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007feb1e0cc000)
/lib64/ld-linux-x86-64.so.2 (0x00007feb21440000)

So, who provides that?

$ dpkg --search /usr/lib/x86_64-linux-gnu/libicuuc.so.52
libicu52:amd64: /usr/lib/x86_64-linux-gnu/libicuuc.so.52

There's your clue:

solution

$ sudo apt-get install libicu52
Sign up to request clarification or add additional context in comments.

3 Comments

sehe you always amaze :-) i followed similar steps on my gentoo box to get my boost happy. in my case, i bumped my box without rebuilding boost, and boost wasn't finding libicu, because it was looking for v57 when i'd moved to v58. rebuild boost, fixed. thanks for another helpful answer.
Two years later, and I'm here again to find the solution. One of these years I'll remember. :-)
@moodboom I usually run into my own answers. I just think SO is a very large shared notepad :)
0

I have put your code in test.cpp

and

I just tested compiling your code like this:

g++ test.cpp -lboost_regex

I don’t have any error right now, it's working

of course I used this command before:

sudo apt-get install libboost-all-dev

tested under ubuntu 15.04

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.