文章描述了在Ubuntu系统中安装、查看和卸载TBB库的步骤,包括使用`sudoaptinstall`命令安装,`dpkg-l`检查版本,以及`sudoapt-getremove`卸载。当遇到CMake找不到tbb_stddef.h文件的错误时,提供了一个解决方案,即在/usr/include/tbb目录下创建该文件并添加必要内容。最后,文章给出了一个简单的C++程序来测试TBB库是否正确工作。
摘要由CSDN通过智能技术生成
$ dpkg -l | grep libtbb
ii libtbb2:amd64 2020.3-2 amd64 parallelism library for C++ - runtime library
ii libtbb2-dev:amd64 2020.3-2 amd64 parallelism library for C++ - development files
sudo apt-get remove libtbb2:amd64
#include <iostream>
#include <tbb/tbb.h>
int main() {
tbb::parallel_for(0, 13, 1, [](int i) {
std::cout << i << std::endl;
std::cout << "Hello World!" << std::endl;
});
return 0;
$ g++ test.cc -ltbb && ./a.out
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
CMake Error at cmake/FindTBB.cmake:397 (file):
file STRINGS file "/usr/include/tbb/tbb_stddef.h" cannot be read.
Call Stack (most recent call first):
CMakeLists.txt:16 (find_package)
解决办法:在/usr/include/tbb
目录下新加一个文件tbb_stddef.h
.
$ cd /usr/include/tbb
$ sudo vim tbb_stddef.h
tbb_stddef.h
:
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#ifndef __TBB_tbb_stddef_H
#define __TBB_tbb_stddef_H
#define TBB_VERSION_MAJOR 2020
#define TBB_VERSION_MINOR 2
#define TBB_INTERFACE_VERSION 11102
#define TBB_INTERFACE_VERSION_MAJOR TBB_INTERFACE_VERSION/1000
#define TBB_COMPATIBLE_INTERFACE_VERSION 2
#define __TBB_STRING_AUX(x) #x
#define __TBB_STRING(x) __TBB_STRING_AUX(x)
#if !defined RC_INVOKED
* @defgroup algorithms Algorithms
* @defgroup containers Containers
* @defgroup memory_allocation Memory Allocation
* @defgroup synchronization Synchronization
* @defgroup timing Timing
* @defgroup task_scheduling Task Scheduling
* \mainpage Main Page
* Click the tabs above for information about the
* - <a href="./modules.html">Modules</a> (groups of functionality) implemented by the library
* - <a href="./annotated.html">Classes</a> provided by the library
* - <a href="./files.html">Files</a> constituting the library.
* Please note that significant part of TBB functionality is implemented in the form of
* template functions, descriptions of which are not accessible on the <a href="./annotated.html">Classes</a>
* tab. Use <a href="./modules.html">Modules</a> or <a href="./namespacemembers.html">Namespace/Namespace Members</a>
* tabs to find them.
* Additional pieces of information can be found here
* - \subpage concepts