Ubuntu12.04下Boost安装和使用
安装
- 官网下载最新的库,目前最新为:boost_1_58_0.tar.gz。
- 解压,安装
tar -zxvf boost_1_58_0.tar.gz
cd boost_1_58_0
sudo ./bootstrap.sh
sudo ./b2 install
- 相关依赖库
build-essential、libc6-dev、libc6-dev、gcc、g++、 make、dpkg-dev
使用
使用分两种情况
+ 第一类,无需编译直接调用 boost_1_58_0目录的头文件
+ 第二类,需要编译boost采用调用
常见问题
- 问题一
undefined reference to boost::system::generic_category()
解决办法:编译时添加-lboost_system
- 问题二
undefined reference to `pthread_key_create'
解决办法: 编译时添加-lboost_thread
- 问题三
./testboost
error while loading shared libraries: libboost_system.so.1.58.0: cannot open shared object file: No such file or directory
ubuntu@ubuntu:~/workspace/testboost/Debug$ ldd testboost
linux-gate.so.1 => (0xb7704000)
libboost_system.so.1.58.0 => not found
libboost_thread.so.1.58.0 => not found
libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0xb757b000)
libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xb755d000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb73b3000)
libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xb7398000)
libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb736c000)
/lib/ld-linux.so.2 (0xb7705000)
解决办法:向ld.so.conf文件中添加libboost_system.so.1.58.0
所在的目录路径
sudo vim /etc/ld.so.conf
sudo ldconfig