I'm having trouble getting a boost program to compile. The example I'm trying to compile is here: http://rosettacode.org/wiki/Web_scraping#C.2B.2B
This is what happens when I try to compile:
% g++ -Wall test.c -lboost_regex -lboost_system -lboost_thread
/tmp/ccJSxOji.o: In function `boost::exception_detail::error_info_injector<std::length_error>::error_info_injector(boost::exception_detail::error_info_injector<std::length_error> const&)':
test.c:(.text._ZN5boost16exception_detail19error_info_injectorISt12length_errorEC2ERKS3_[_ZN5boost16exception_detail19error_info_injectorISt12length_errorEC5ERKS3_]+0x53): undefined reference to `std::length_error::~length_error()'
/tmp/ccJSxOji.o: In function `boost::exception_detail::error_info_injector<std::length_error>::~error_info_injector()':
test.c:(.text._ZN5boost16exception_detail19error_info_injectorISt12length_errorED2Ev[_ZN5boost16exception_detail19error_info_injectorISt12length_errorED5Ev]+0x2e): undefined reference to `std::length_error::~length_error()'
collect2: ld returned 1 exit status
I think I've narrowed the problem down to this line:
boost::asio::streambuf response ;
I'm using gcc 4.6.0, linux of course:
% gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-pc-linux-gnu/4.6.0/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: /build/src/gcc-4.6-20110429/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --enable-gnu-unique-object --enable-linker-build-id --with-ppl --enable-cloog-backend=isl --enable-lto --enable-gold --enable-ld=default --enable-plugin --with-plugin-ld=ld.gold --disable-multilib --disable-libstdcxx-pch --enable-checking=release
Thread model: posix
gcc version 4.6.0 20110429 (prerelease)开发者_如何学C (GCC)
Possibly related thread:
Code using boost::asio::streambuf causes segfault
I hate to answer my own question, but as it turns out, I was bitten by this: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.15' not found
I did some more digging:
% ldd /usr/lib/libboost_regex.so
/usr/lib/libboost_regex.so: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by /usr/lib/libboost_regex.so)
linux-gate.so.1 => (0xb77b3000)
libicuuc.so.46 => /usr/lib/libicuuc.so.46 (0xb7553000)
libicui18n.so.46 => /usr/lib/libicui18n.so.46 (0xb7389000)
libicudata.so.46 => /usr/lib/libicudata.so.46 (0xb650a000)
librt.so.1 => /lib/librt.so.1 (0xb6501000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb6412000)
libm.so.6 => /lib/libm.so.6 (0xb63e8000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0xb63cc000)
libpthread.so.0 => /lib/libpthread.so.0 (0xb63b1000)
libc.so.6 => /lib/libc.so.6 (0xb624b000)
libdl.so.2 => /lib/libdl.so.2 (0xb6246000)
/lib/ld-linux.so.2 (0xb77b4000)
% ldd /usr/lib/libboost_date_time.so
/usr/lib/libboost_date_time.so: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by /usr/lib/libboost_date_time.so)
linux-gate.so.1 => (0xb78cf000)
librt.so.1 => /lib/librt.so.1 (0xb788f000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb77a1000)
libm.so.6 => /lib/libm.so.6 (0xb7777000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0xb775b000)
libpthread.so.0 => /lib/libpthread.so.0 (0xb773f000)
libc.so.6 => /lib/libc.so.6 (0xb75d9000)
/lib/ld-linux.so.2 (0xb78d0000)
In sum, my gcc-libs were out of date. To fix it, I did:
# pacman -Q -o /usr/lib/libstdc++.so.6
/usr/lib/libstdc++.so.6 is owned by gcc-libs 4.6.0-5
# pacman -S gcc-libs
Thanks to everyone who commented, you got me thinking in the right direction.
精彩评论