如何在 Linux 上从源代码安装 TBB 并使其工作 [英] How to install TBB from source on Linux and make it work
问题描述
我想知道如何从源代码安装 TBB 并使其在 Linux 系统上运行.我在使用它时遇到了一些问题,如果我通过包管理器安装 TBB,这些问题就不会出现.
在 TBB 网页中,有一些关于如何执行此操作的指南,例如设置 LD_LIBRARY_PATH
和 CPATH
变量,或获取 tbbvars.sh
文件.即使我这样做,当我尝试编译一个示例时,g++
会说没有找到 tbb
.
所以我的问题是,是否有一种简单的方法来设置所有内容(编译源代码,我应该设置哪些变量...)以便使用 TBB?
谢谢.
注意:提出这个问题时的库版本号是 2(如果我没记错的话).我已经亲自测试了 4.1 版之前的解决方案,但我认为它也适用于当前版本 4.2(更新 3)
,因为构建方法保持不变.
我已经提供了解决方案.我会把它贴在这里,这样它会帮助其他人解决这个话题.
下载最新的稳定源代码并解压,即在
~/tbbsrc
在里面,输入
make
.它应该开始编译 tbb 库和内存分配器.标题在
~/tbbsrc/include
在
~/tbbsrc/build
里面将有两个新文件夹,一个用于发布版本,另一个用于调试版本.这些文件夹的名称类似于architecture_ldVersion_g++Version_kernelVersion
.我建议设置一些变量,例如在您的
~/.bashrc
文件中,例如:
TBB_INSTALL_DIR = $HOME/tbbsrcTBB_INCLUDE = $TBB_INSTALL_DIR/包含TBB_LIBRARY_RELEASE = $TBB_INSTALL_DIR/build/RELEASE_FOLDERTBB_LIBRARY_DEBUG = $TBB_INSTALL_DIR/build/DEBUG_FOLDER
- 让我们尝试一个简单的例子:
//main.cpp#include "tbb/task_scheduler_init.h";int main(int argc, char* argv[]) {//tbb::task_scheduler_init init(tbb::task_scheduler_init::automatic);//隐式 tbb::task_sheduler_init::automatictbb::task_scheduler_init 初始化;返回0;}
- 以发布版本为例进行编译:
g++ main.cpp -I$TBB_INCLUDE -Wl,-rpath,$TBB_LIBRARY_RELEASE -L$TBB_LIBRARY_RELEASE -ltbb
<块引用>
注意:使用-Wl,-rpath,$TBB_LIBRARY_RELEASE
,我们告诉动态链接器在哪里可以找到libtbb.so
- 这应该没问题!
最好的问候!
Apple clang 5.1 的安装: [感谢 rwols 提供信息]
不要输入make
,而是输入make compiler=clang
或make compiler=clang stdlib=libc++
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.
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.sh
file. Even if I do that, when I try to compile an example g++
says that tbb
is not found.
So my question is, is there an easy way to setup everything (compile the source code, what variables should I set...) in order to use 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.
I have come with the solution. I'll post it here so it will help others with this topic.
Download the latest stable source code and uncompress it, i.e in
~/tbbsrc
Inside, type
make
. It should start compiling the tbb library and the memory allocators.The headers are in
~/tbbsrc/include
Inside
~/tbbsrc/build
will be two new folders, one for the release version and the other for the debug version. Those folders are named likearchitecture_ldVersion_g++Version_kernelVersion
.I recommend setting some variables, for example in your
~/.bashrc
file, like:
TBB_INSTALL_DIR = $HOME/tbbsrc
TBB_INCLUDE = $TBB_INSTALL_DIR/include
TBB_LIBRARY_RELEASE = $TBB_INSTALL_DIR/build/RELEASE_FOLDER
TBB_LIBRARY_DEBUG = $TBB_INSTALL_DIR/build/DEBUG_FOLDER
- Let's try a simple example:
// 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;
}
- To compile, for example, with the release version:
g++ main.cpp -I$TBB_INCLUDE -Wl,-rpath,$TBB_LIBRARY_RELEASE -L$TBB_LIBRARY_RELEASE -ltbb
Note: with
-Wl,-rpath,$TBB_LIBRARY_RELEASE
, we are telling the dynamic linker where to findlibtbb.so
- And that should work fine!
Best regards!
Installation for Apple clang 5.1: [thanks to rwols for the info]
Instead of typing make
, type make compiler=clang
or make compiler=clang stdlib=libc++
这篇关于如何在 Linux 上从源代码安装 TBB 并使其工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!