Linux 如何为新安装的 Boost 添加编译器包含路径和链接器库路径?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4123618/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 23:49:50  来源:igfitidea点击:

How to add compiler include paths and linker library paths for newly installed Boost?

c++linuxboostbuildrpm

提问by Nav

I have RHEL 5.2, with Boost 1.33 installed. I downloaded boost_1_44_0.tar.bz2. and built it. On completion it showed:

我有 RHEL 5.2,安装了 Boost 1.33。我下载了 boost_1_44_0.tar.bz2。并建造了它。完成后显示:

The Boost C++ Libraries were successfully built!

The following directory should be added to compiler include paths:

    /home/dfe/Archive/boost_1_44_0

The following directory should be added to linker library paths:

    /home/dfe/Archive/boost_1_44_0/stage/lib
  1. How do I add the above mentioned include paths?
  2. When I do "rpm -q boost", it shows boost-1.33.1-10.el5. Why is that so, when I've installed version 1.44?
  3. Is there a better way to install the latest version of Boost?
  1. 如何添加上述包含路径?
  2. 当我执行“rpm -q boost”时,它显示 boost-1.33.1-10.el5。为什么会这样,当我安装了 1.44 版时?
  3. 有没有更好的方法来安装最新版本的 Boost?

采纳答案by Nav

First, I removed the existing boost rpm using

首先,我删除了现有的 boost rpm 使用

rpm -e boost-1.33.1-10.el5

A message is displayed saying "error: "boost" specifies multiple packages"

显示一条消息“错误:“boost”指定多个包”

Then tried:

然后尝试:

rpm -e --allmatches boost

(I don't remember whether I typed 'boost' or 'boost-1.33.1-10.el5')

(我不记得我输入的是“boost”还是“boost-1.33.1-10.el5”)

The packages with dependencies were shown. I did:

显示了具有依赖性的包。我做了:

rpm -e [packagename1]
rpm -e [packagename2]

and so on and then did:

等等然后做了:

rpm -e --allmatches

This erased boost completely from my system.

这完全从我的系统中删除了提升。

Then I extracted boost_1_44_0.tar.bz2 using tar -xvjf boost_1_44_0.tar.bz2 and ran bootstrap with:

然后我使用 tar -xvjf boost_1_44_0.tar.bz2 提取 boost_1_44_0.tar.bz2 并运行引导程序:

./bootstrap.sh

Then ran bjam as:

然后将 bjam 运行为:

./bjam install

That's it! Boost got installed on my system, and I didn't have to specify any of the linker options while compiling programs! Yay! Now the 'rpm -q boost' command shows that there is no package installed.

就是这样!Boost 安装在我的系统上,我在编译程序时不必指定任何链接器选项!好极了!现在'rpm -q boost'命令显示没有安装包。

回答by jRJ

You have to include these directories into makefile which you would use to build your application

您必须将这些目录包含在用于构建应用程序的 makefile 中

CC -I/home/dfe/Archive/boost_1_44_0 -L/home/dfe/Archive/boost_1_44_0/stage/lib yourprogram.cpp

-I option Adds dir to the list of directories that are searched for #include files.

-I 选项 将 dir 添加到搜索 #include 文件的目录列表中。

-L option adds dir to the list of directories searched for libraries by linker

-L 选项将 dir 添加到链接器搜索库的目录列表中

CC is sun compiler...

CC是sun编译器...

回答by der_michael

Just add the paths to your .bashrc or .profile (or whatever floats your boat) like this:

只需将路径添加到您的 .bashrc 或 .profile(或任何漂浮在您的船上的东西),如下所示:

export LIBS="-L/home/dfe/Archive/boost_1_44_0/stage/lib"
export CPPFLAGS="-I/home/dfe/Archive/boost_1_44_0"

回答by user2716834

There are always three steps to install software on Linux systems:

在 Linux 系统上安装软件总是需要三个步骤:

  1. configure — "check"
  2. make — "build software in current directory"
  3. make install — "copy files to the systems so the other software can use this software"
  1. 配置——“检查”
  2. make — "在当前目录中构建软件"
  3. make install — “将文件复制到系统,以便其他软件可以使用该软件”

You likely did the equivalent of makebut did not do the equivalent of make install. You need to run

您可能做了相当于make但没有做相当于make install. 你需要跑

sudo ./b2 install

after running ./b2

跑完后 ./b2