我不使用 TBB,但我收到与 TBB 相关的链接器错误

问题描述

我有一些测试代码,其中包括

#include <stddef.h>
#include <stdio.h>
#include <algorithm>
#include <chrono>
#include <execution>
#include <random>
#include <ratio>
#include <vector>

当我使用 Clang/Linux 构建它时,我收到这些链接错误,这似乎暗示我正在使用 TBB 库(我不是):

[1/2] /usr/bin/clang++ -IAlgosGPGPU.p -I. -I../AlgosGPGPU -fcolor-diagnostics -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -std=c++20 -g -MD -MQ AlgosGPGPU.p/main.cpp.o -MF AlgosGPGPU.p/main.cpp.o.d -o AlgosGPGPU.p/main.cpp.o -c ../AlgosGPGPU/main.cpp
[2/2] /usr/bin/clang++  -o AlgosGPGPU AlgosGPGPU.p/main.cpp.o -Wl,--as-needed -Wl,--no-undefined
Failed: AlgosGPGPU 
/usr/bin/clang++  -o AlgosGPGPU AlgosGPGPU.p/main.cpp.o -Wl,--no-undefined
/usr/bin/ld: AlgosGPGPU.p/main.cpp.o: in function `void tbb::interface7::internal::isolate_impl<void,__pstl::__tbb_backend::__parallel_stable_sort<__pstl::execution::v1::parallel_unsequenced_policy const&,__gnu_cxx::__normal_iterator<double*,std::vector<double,std::allocator<double> > >,std::less<double>,__pstl::__internal::__pattern_sort<__pstl::execution::v1::parallel_unsequenced_policy const&,std::integral_constant<bool,true> >(__pstl::execution::v1::parallel_unsequenced_policy const&,true>,true>)::{lambda()#1}::operator()() const::{lambda(__gnu_cxx::__normal_iterator<double*,std::less<double>)#1}>(__pstl::execution::v1::parallel_unsequenced_policy const&,std::less<double>)#1},unsigned long)::{lambda()#1} const>(__pstl::__tbb_backend::__parallel_stable_sort<__pstl::execution::v1::parallel_unsequenced_policy const&,unsigned long)::{lambda()#1} const&)':
/usr/include/tbb/task_arena.h:216: undefined reference to `tbb::interface7::internal::isolate_within_arena(tbb::interface7::internal::delegate_base&,long)'
/usr/bin/ld: AlgosGPGPU.p/main.cpp.o: in function `tbb::tbb_allocator<double>::allocate(unsigned long,void const*)':
/usr/include/tbb/tbb_allocator.h:86: undefined reference to `tbb::internal::allocate_via_handler_v3(unsigned long)'
/usr/bin/ld: AlgosGPGPU.p/main.cpp.o: in function `operator new(unsigned long,tbb::internal::allocate_root_proxy const&)':
/usr/include/tbb/task.h:1145: undefined reference to `tbb::internal::allocate_root_proxy::allocate(unsigned long)'
/usr/bin/ld: AlgosGPGPU.p/main.cpp.o: in function `operator delete(void*,tbb::internal::allocate_root_proxy const&)':
/usr/include/tbb/task.h:1149: undefined reference to `tbb::internal::allocate_root_proxy::free(tbb::task&)'
/usr/bin/ld: AlgosGPGPU.p/main.cpp.o: in function `task':
/usr/include/tbb/task.h:625: undefined reference to `vtable for tbb::task'
/usr/bin/ld: AlgosGPGPU.p/main.cpp.o: in function `operator new(unsigned long,tbb::internal::allocate_continuation_proxy const&)':
/usr/include/tbb/task.h:1163: undefined reference to `tbb::internal::allocate_continuation_proxy::allocate(unsigned long) const'
/usr/bin/ld: AlgosGPGPU.p/main.cpp.o: in function `operator delete(void*,tbb::internal::allocate_continuation_proxy const&)':
/usr/include/tbb/task.h:1167: undefined reference to `tbb::internal::allocate_continuation_proxy::free(tbb::task&) const'
...

如果我注释掉这行代码

sort(std::execution::par_unseq,sorted.begin(),sorted.end());

程序构建成功。

这是怎么回事? clang 在下面使用 TBB 吗?

解决方法

我相信大多数 Linux 发行版上的 clang 都与 GNU libstdc++ 相关联,后者的 const serverResponse = await fetch('https://<MYAPP>.auth0.com/api/v2/users/' + user.sub,{ headers:{ Authorization: 'Bearer ' + accessToken } }) 支持确实需要 libtbb。这埋在the documentation中,搜索“Note 3”。因此,您必须安装 libtbb 并将 <execution> 添加到您的链接命令中。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...