我希望使用GCC9.3来运行C++17中的执行策略,使用std算法。
我已经下载了https://github.com/oneapi-src/oneTBB/releases/download/v2021.1.1/oneapi-tbb-2021.1.1-lin.tgz,但是我遇到了一个错误,即“task”类未定义,甚至在https://www.ibm.com/developerworks/aix/library/au-intelthreadbuilding/index.html的“hello world”示例中也出现了这个问题。
我得到以下错误:
我正在编译:使用以下命令:
谢谢。
我已经下载了https://github.com/oneapi-src/oneTBB/releases/download/v2021.1.1/oneapi-tbb-2021.1.1-lin.tgz,但是我遇到了一个错误,即“task”类未定义,甚至在https://www.ibm.com/developerworks/aix/library/au-intelthreadbuilding/index.html的“hello world”示例中也出现了这个问题。
#include "tbb/tbb.h"
#include <iostream>
using namespace tbb;
using namespace std;
class first_task : public task {
public:
task* execute( ) {
cout << "Hello World!\n";
return NULL;
}
};
int main( )
{
task_scheduler_init init(task_scheduler_init::automatic);
first_task& f1 = *new(tbb::task::allocate_root()) first_task( );
tbb::task::spawn_root_and_wait(f1);
}
我得到以下错误:
test.cpp:55:32: error: expected class-name before '{' token
55 | class first_task : public task {
| ^
test.cpp:57:5: error: 'task' does not name a type
57 | task* execute( ) {
| ^~~~
test.cpp: In function 'int main()':
test.cpp:65:5: error: 'task_scheduler_init' was not declared in this scope
65 | task_scheduler_init init(task_scheduler_init::automatic);
| ^~~~~~~~~~~~~~~~~~~
test.cpp:66:38: error: 'allocate_root' is not a member of 'tbb::v1::task'
66 | first_task& f1 = *new(tbb::task::allocate_root()) first_task( );
| ^~~~~~~~~~~~~
test.cpp:67:16: error: 'spawn_root_and_wait' is not a member of 'tbb::v1::task'
67 | tbb::task::spawn_root_and_wait(f1);
| ^~~~~~~~~~~~~~~~~~~
我正在编译:使用以下命令:
g++ -I<path_to_tbb>/oneapi-tbb-2021.1.1/include/oneapi -I<path_to_tbb>/oneapi-tbb-2021.1.1/include/oneapi/tbb -I<path_to_tbb>/oneapi-tbb-2021.1.1/include -L<path_to_tbb>/oneapi-tbb-2021.1.1/lib/intel64/gcc4.8/ test.cpp -o test
从<path_to_tbb>运行source env/var.h
没有帮助,我做错了什么吗?谢谢。
gcc4.8
看起来非常错误,因为GCC >= 5中的libstdc++在设计上具有ABI不兼容性,以符合C++11标准,除非它专门配置为向后兼容。 - FrankHBapt install libtbb-dev
命令。然后使用g++ test.cpp -o test $(pkg-config --libs --cflags tbb)
进行编译。 - G. Sliepen