如何在 Linux 上从源代码安装 TBB 并使其工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10726537/
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-06 06:27:37  来源:igfitidea点击:

How to install TBB from source on Linux and make it work

c++linuxcompilationinstallationtbb

提问by Adri C.S.

I would like to know how to install TBB from source and make it work on a Linux system. I have had some problems when it comes using it, problems that don't appear if I install TBB via the package manager.

我想知道如何从源代码安装 TBB 并使其在 Linux 系统上工作。我在使用它时遇到了一些问题,如果我通过包管理器安装 TBB,这些问题就不会出现。

In the TBB webpage, there are some guidelines on how about to do this, like setting the LD_LIBRARY_PATH and CPATH variables, or sourcing the tbbvars.shfile. Even if I do that, when I try to compile an example g++says that tbbis not found.

在 TBB 网页中,有一些关于如何执行此操作的指南,例如设置 LD_LIBRARY_PATH 和 CPATH 变量,或获取tbbvars.sh文件。即使我这样做,当我尝试编译一个示例时,g++ 会找不到 tbb

So the question is if it's an easy way on how to setup everything(compile the source code, what variables should I set...) in order to use TBB.

所以问题是,为了使用TBB,这是否是一种设置所有内容(编译源代码,我应该设置哪些变量...)的简单方法。

Thanks.

谢谢。

NOTE:The library version number when this question was asked was 2 (if I recall correctly). I have personally tested the solution up to version 4.1, but I think it should work too for current version 4.2 (update 3)since the building method remains the same.

注意:提出这个问题时的库版本号是 2(如果我没记错的话)。我亲自测试了 4.1 版之前的解决方案,但我认为它也适用于当前版本,4.2 (update 3)因为构建方法保持不变。

采纳答案by Adri C.S.

I have come with the solution. I'll post it here so it will help others with this topic.

我带来了解决方案。我会把它贴在这里,这样它会帮助其他人解决这个话题。

1) Download the latest stable source code and uncompress it, i.e in ~/tbbsrc

1) 下载最新的稳定源代码并解压,即在~/tbbsrc

2) Inside, type make. It should start compiling the tbb library and the memory allocators.

2)在里面,输入make。它应该开始编译 tbb 库和内存分配器。

3) The headers are in ~/tbbsrc/include

3) 头文件在 ~/tbbsrc/include

4) Inside ~/tbbsrc/build will be two new folders, one for the release version and the other for the debug version. Those folders are named like "architecture_ldVersion_g++Version_kernelVersion".

4) ~/tbbsrc/build 里面会有两个新文件夹,一个是发布版本,另一个是调试版本。这些文件夹的名称类似于“architecture_ldVersion_g++Version_kernelVersion”。

5) I recommend setting some variables, for example in the .bashrc file, like:

5) 我建议设置一些变量,例如在 .bashrc 文件中,例如:

  1. TBB_INSTALL_DIR = $HOME/tbbsrc
  2. TBB_INCLUDE = $TBB_INSTALL_DIR/include
  3. TBB_LIBRARY_RELEASE = $TBB_INSTALL_DIR/build/RELEASE_FOLDER
  4. TBB_LIBRARY_DEBUG = $TBB_INSTALL_DIR/build/DEBUG_FOLDER
  1. TBB_INSTALL_DIR = $HOME/tbbsrc
  2. TBB_INCLUDE = $TBB_INSTALL_DIR/包含
  3. TBB_LIBRARY_RELEASE = $TBB_INSTALL_DIR/build/RELEASE_FOLDER
  4. TBB_LIBRARY_DEBUG = $TBB_INSTALL_DIR/build/DEBUG_FOLDER

6) Let's try a simple example:

6)让我们尝试一个简单的例子:

// main.cpp
#include "tbb/task_scheduler_init.h"

int main(int argc, char* argv[]) {
  //  tbb::task_scheduler_init init(tbb::task_scheduler_init::automatic);
  // implicit tbb::task_sheduler_init::automatic
  tbb::task_scheduler_init init;
  return 0;
}

7) To compile, for example, with the release version:

7) 以发布版本为例进行编译:

g++ main.cpp -I$TBB_INCLUDE -Wl,-rpath,$TBB_LIBRARY_RELEASE -L$TBB_LIBRARY_RELEASE -ltbb

With -Wl,-rpath,$TBB_LIBRARY_RELEASEwe are telling the dynamic linker where to find libtbb.so

随着-Wl,-rpath,$TBB_LIBRARY_RELEASE我们告诉动态连接器在哪里可以找到libtbb.so

8) And that should work fine!

8)这应该可以正常工作!

Best regards!

此致!

Installation for Apple clang 5.1:[thanks to rwols for the info]

Apple clang 5.1 的安装:[感谢 rwols 提供的信息]

Instead of typing make, type make compiler=clangor make compiler=clang stdlib=libc++

而不是打字make,键入make compiler=clangmake compiler=clang stdlib=libc++

回答by Bob Baxley

https://github.com/wjakob/tbbseems to be the way to go.

https://github.com/wjakob/tbb似乎是要走的路。

git clone https://github.com/wjakob/tbb.git
cd tbb/build
cmake ..
make -j
sudo make install