【发布时间】:2021-04-07 18:54:31
【问题描述】:
我想使用 GCC9.3 的 C++17 执行策略运行标准算法。
我已经下载了https://github.com/oneapi-src/oneTBB/releases/download/v2021.1.1/oneapi-tbb-2021.1.1-lin.tgz
但我收到一个错误,即“任务”类未定义 即使是来自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
从 source env/var.h 没有帮助
我做错了吗?
谢谢
【问题讨论】:
-
前两个包含路径不是必需的。试试更短的命令
g++ -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 -
不确定这里发生了什么,而且似乎没有多大关系,但
gcc4.8对我来说看起来很错误,因为 GCC >= 5 中的 libstdc++ 在设计上与以前的二进制文件不兼容(对于 C++ 11 一致性),除非它是专门为向后兼容而配置的。 -
您需要将您的应用程序与 TBB 关联,即在命令行中添加
-ltbb,例如:solarianprogrammer.com/2019/05/09/… 但是,您也有编译器错误。尝试使用选项-Etrhat 仅执行预处理器步骤并查看生成的文件。此外,错误消息上的行号与您向我们显示的来源不对应。 . -
如果您在 Linux 上,请检查您的发行版是否带有用于 tbb 的软件包,例如在基于 Debian 的发行版上,
apt install libtbb-dev可能有效。然后用g++ test.cpp -o test $(pkg-config --libs --cflags tbb)编译。 -
您好,感谢您的 cmets。 @SM - 即使使用更短的命令,我仍然遇到同样的问题