3

我安装了 Ubuntu 11.10 和内核版本 3.0.0-23-generic 和 +/- 默认情况下,我得到以下 Boost 版本 1.46.1,它安装在/usr/include/boostand下/usr/lib

bravegag@Zeus:~/code/roofline/tool$ dpkg --get-selections | grep boost
libboost-date-time1.46.1        install
libboost-dev                    install
libboost-iostreams1.46.1        install
libboost-program-options1.46.1  install
libboost-serialization1.46.1    install
libboost-thread1.46.1           install
libboost1.46-dev                install

我可以尝试通过标准的 Ubuntu 方式更新它,但这很可能意味着我需要获得一些第三方 ppa 并作为副作用拉出很多废话,这会使我的系统不稳定,我不希望那样。所以我从源代码安装了 Boost 1.50,它安装在/usr/local/include/boost/usr/local/lib.

一个 CMake 项目我选择了 1.50 版本没有问题。但是,我使用的一个使用“默认”系统设置编译和链接的工具最终选择了 1.46.1 版本并导致错误消息src/utils.h:17:25: error: ‘boost::BOOST_FOREACH’ has not been declared,因此显然没有选择 1.50 版本。

我尝试像这样覆盖默认的 g++/gcc Boost 版本:

export CPLUS_INCLUDE_PATH=/usr/local/include/boost/:$CPLUS_INCLUDE_PATH   
export LIBRARY_PATH=/usr/local/lib/:$LIBRARY_PATH

但这也不能解决问题……我的问题是我能不能简单地清除所有旧的 Boost 1.46 安装并转移到默认安装/usr/include/usr/lib1.50 安装?这样做会导致我的系统崩溃吗?我不想冒另一个重新安装狂潮的风险。

4

2 回答 2

4

I could try updating it by the standard Ubuntu means but this will most likely imply I need to get some third party ppa and pull as side effect lot of crap that will make my system unstable

You can add a PPA, install only the packages you want and (if the PPA contains more than just the Boost libraries) remove it, so that no other package will get auto-updated. I think that's the easiest way to go.

However, a tool I am using that compiles and links using the "default" system settings ends up picking the 1.46.1

What kind of tool is it? Maybe you can configure it to use Boost from a custom location? If it's gcc-based, making it pass -I and -L flags to the compiler and linker might help.

can I not simply sweep out all those old Boost 1.46 installations and move over to the default /usr/include and /usr/lib the 1.50 installation? would doing this cause my system to break?

In most GNU/Linux distributions (with Ubuntu among them) the /usr prefix is reserved for software managed with the distribution's package manager. Installing a non-packaged software there will work at first, but you may have some trouble (e.g. package manager complaints) when some package will actually contain the same files. That's why for manually compiled, non-packaged software it's a common practice to use other prefixes like /usr/local or /opt/something.

Most shared libraries are versioned, so it is safe to have multiple versions of them installed on the same system at the same time. Particularly, you can have multiple versions of Boost runtime packages in Ubuntu. If you still want to make a manual install of Boost to /usr, you don't have to remove the old Boost runtime version, which is good if you found out that some important software packages depend on them.

However, before installing your newly compiled Boost to /usr, firstly remove from your system all *boost*dev packages (and all other *dev packages that depend on them), because they contain the header files (many Boost components are header-only), static libraries and symbolic links to particular runtime libraries version.

To confirm that it works, I just compiled and installed Boost 1.51 to /usr on my Ubuntu 11.04 using this method and nothing broke. Aptitude still uses Boost 1.42:

$ ldd /usr/bin/aptitude | grep boost
libboost_iostreams.so.1.42.0 => /usr/lib/libboost_iostreams.so.1.42.0 (0x00007f536ee77000)

And newly compiled programs use the new version:

$ g++ my-boost-test.c -lboost_thread -o my-boost-test
$ ldd my-boost-test | grep boost
libboost_thread.so.1.51.0 => /usr/lib/libboost_thread.so.1.51.0 (0x00007f543d1df000)
libboost_chrono.so.1.51.0 => /usr/lib/libboost_chrono.so.1.51.0 (0x00007f543c49e000)
libboost_system.so.1.51.0 => /usr/lib/libboost_system.so.1.51.0 (0x00007f543c29a000)
于 2012-08-26T13:59:57.933 回答
2

你的问题

我的问题是我能不能简单地清除所有旧的 Boost 1.46 安装并转移到默认的 /usr/include 和 /usr/lib 1.50 安装?这样做会导致我的系统崩溃吗?我不想冒另一个重新安装狂潮的风险。

得到一个明确的是的,它可以,因为包之间有很多反向依赖关系,因此依赖于特定版本。例如在我的 Ubuntu 系统上(升级了好几次)

edd@max:~$ dpkg -l | grep libboost-date-time | cut -c-72
ii  libboost-date-time-dev                        1.48.0.2              
rc  libboost-date-time1.38.0                      1.38.0-6ubuntu6       
ii  libboost-date-time1.40.0                      1.40.0-6ubuntu1       
rc  libboost-date-time1.42.0                      1.42.0-4ubuntu2       
ii  libboost-date-time1.46-dev                    1.46.1-7ubuntu3       
ii  libboost-date-time1.46.1                      1.46.1-7ubuntu3       
edd@max:~$ 

我们看到 1.38 和 1.42 已被完全替换,但仍有其他软件包依赖于 1.40 和 1.46,即使我的开发版本现在是 1.48。

所以你最好的办法是......如果存在这样的版本,从 PPA 获得 1.50 甚至 1.51,或者安装到/usr/local并相应地调整你的 makefile / configure / cmake / ... 设置。

于 2012-08-26T14:05:04.320 回答