【问题标题】:Uninstall boost and install another version卸载 boost 并安装另一个版本
【发布时间】:2011-12-08 11:30:55
【问题描述】:

我已经使用命令sudo apt-get install libboost-dev libboost-doc 在 Linux Mint 12 上安装了 boost 库,该命令安装了存储库中可用的默认版本。但是,我要做的项目需要1.44版本的boost。如何卸载默认(当前)版本 1.46 并安装 1.44?

我在 boost website 上找不到从 .tar.gz 包安装 boost 的文档。

【问题讨论】:

  • 我正在尝试进行安装,但我遇到了一些错误,我正在执行第 6 点,并且 $ c++ -I path/to/boost_1_48_0 example.cpp -o example \ ~ /boost/stage/lib/libboost_regex-gcc34-mt-d-1_36.a,我不明白该命令,它会产生输出 g++ -I /usr/local/boost_1_48_0 example.cpp -o example -L~/boost/ stage/lib/ -lboost_regex-gcc34-mt-d-1_36 /usr/bin/ld: 找不到 -lboost_regex-gcc34-mt-d-1_36 collect2: ld 返回 1 个退出状态

标签: c++ linux boost installation


【解决方案1】:

Boost 可以通过两种方式安装

  • Deb 包
  • wget 并手动安装

在某些情况下,我们可能同时安装了两种类型,这可能会导致版本错误。让我们看看如何卸载两者。

sudo apt-get update

# to uninstall deb version
sudo apt-get -y --purge remove libboost-all-dev libboost-doc libboost-dev
# to uninstall the version which we installed from source
sudo rm -f /usr/lib/libboost_*

那么如果不满足就需要安装其他依赖

sudo apt-get -y install build-essential g++ python-dev autotools-dev libicu-dev libbz2-dev

让我们从link 下载我们需要的增强版本。我正在下载 1.54 版本。然后解压并安装它。

# go to home folder
cd
wget http://downloads.sourceforge.net/project/boost/boost/1.54.0/boost_1_54_0.tar.gz
tar -zxvf boost_1_54_0.tar.gz
cd boost_1_54_0
# get the no of cpucores to make faster
cpuCores=`cat /proc/cpuinfo | grep "cpu cores" | uniq | awk '{print $NF}'`
echo "Available CPU cores: "$cpuCores
./bootstrap.sh  # this will generate ./b2
sudo ./b2 --with=all -j $cpuCores install

现在让我们检查安装的版本

cat /usr/local/include/boost/version.hpp | grep "BOOST_LIB_VERSION"

你会看到类似下面的东西

//  BOOST_LIB_VERSION must be defined to be the same as BOOST_VERSION
#define BOOST_LIB_VERSION "1_54"

已安装 boost 1.54 版

就是这样,它对我有用。如果您遇到任何问题,请告诉我。

【讨论】:

  • 对于其他版本的 boost,可能需要在 ./b2 之前运行 boostrap..../bootstrap.sh --with-libraries=atomic,date_time,exception,filesystem,iostreams,locale,program_options,regex,signals,system,test,thread,timer,log
  • @ram DEB 版本还需要sudo apt autoremove 吗?
  • @ram 我们不应该在/usr/include而不是/usr/local/include寻找版本吗?
  • @CloudCho 取决于安装,它将出现在/usr/include/usr/local/include 中。如果您收到No such file or directory,请尝试另一种。
  • 但是我想把它安装在usr/include上,我该怎么做呢?
【解决方案2】:

你可以卸载

apt-get --purge remove libboost-dev libboost-doc

从 boost 网站下载你需要的包,解压并按照解压目录中 index.html 中的“入门”说明进行操作。

【讨论】:

  • 我已经按照你说的做了,但是有 12 个东西没有安装,52 个被跳过,这正常吗??
  • 是的,这很正常,除非其中一个未构建的软件包是您将依赖的软件包,否则可能没问题,但根据我的经验,将提供更常用的核心软件包,并且一些不太常用的软件包是那些在所有平台上都不能很好构建的软件包。所以只要运行它,它可能会没事的。
  • 然后:apt-get autoremove
【解决方案3】:

测试工作的 Ubuntu 20.04 使用我的脚本在 ubuntu 20.04 中卸载旧版本的 boost 并按照上面的 rams 说明进行操作

#!/bin/bash
sudo apt-get -y --purge remove libboost-all-dev libboost-doc libboost-dev
echo "clear boost dir"
sudo rm -r /usr/local/lib/libboost*
sudo rm -r /usr/local/include/boost
sudo rm -f /usr/lib/libboost_*
sudo rm -r /usr/include/boost

【讨论】:

    【解决方案4】:

    降级您的增强版本。我不熟悉 Mint,但假设它是基于 deb 的,你可以这样做:

    apt-cache show libboost-dev
    

    查看所有可安装版本并安装特定版本

    sudo apt-get install libboost-dev=1.42.0.1
    

    还有主要的 boost 版本的便利包:

    sudo apt-get install libboost1.44-dev
    

    【讨论】:

    • 干得好,但它不起作用:E:未找到 'libboost-dev' 的版本 '1.44'
    • 谢谢,但不再起作用...你能在我的问题的评论中解释一下我发生了什么吗??
    • Mint 等发行版淘汰旧版本的软件包。它不会找到 1.44,因为该文件不再存在。 (因为可以使用较新的版本。)他们不能永远保留每个旧版本。
    【解决方案5】:

    正如@savamane 所写,您可以使用以下命令卸载它

    apt-get --purge remove libboost-dev libboost-doc

    按照建议here 安装.deb 软件包的另一个建议。 (不过,请下载适合您架构的那个)。

    对于仍受支持的发行版,您只需在 http://packages.ubuntu.com/ 的发行版中搜索软件包即可。例如libboost-system1.46.1 可以在precise -> Libraries 选项卡下找到。

    对于不受支持的发行版,仍有机会在以下位置找到它们 http://archive.ubuntu.com/。例如,libboost-all-dev_1.40.0.1_amd64.deb 可以在 http://archive.ubuntu.com/ubuntu/pool/universe/b/boost-defaults/.

    【讨论】:

      【解决方案6】:

      这是您安装特定 Boost 版本的方式:

      cd boost_1_54_0/
      
      ./bootstrap.sh --with-libraries=atomic,date_time,exception,filesystem,iostreams,locale,program_options,regex,signals,system,test,thread,timer,log
      
      sudo ./b2 install
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-06-03
        • 1970-01-01
        • 2023-03-24
        • 2017-01-07
        • 2021-05-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多