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

I do not use TBB, but I get linker errors related to TBB

提问人:Pietro 提问时间:6/6/2021 更新时间:6/6/2021 访问量:858

问:

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

#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,--as-needed -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&, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, std::less<double>, std::integral_constant<bool, true> >(__pstl::execution::v1::parallel_unsequenced_policy const&, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, std::less<double>, std::integral_constant<bool, true>, std::integral_constant<bool, true>, std::integral_constant<bool, true>)::{lambda()#1}::operator()() const::{lambda(__gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, std::less<double>)#1}>(__pstl::execution::v1::parallel_unsequenced_policy const&, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, __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&, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, std::less<double>, std::integral_constant<bool, true> >(__pstl::execution::v1::parallel_unsequenced_policy const&, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, std::less<double>, std::integral_constant<bool, true>, std::integral_constant<bool, true>, std::integral_constant<bool, true>)::{lambda()#1}::operator()() const::{lambda(__gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, std::less<double>)#1}, unsigned long)::{lambda()#1} const>(__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&, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, std::less<double>, std::integral_constant<bool, true> >(__pstl::execution::v1::parallel_unsequenced_policy const&, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, std::less<double>, std::integral_constant<bool, true>, std::integral_constant<bool, true>, std::integral_constant<bool, true>)::{lambda()#1}::operator()() const::{lambda(__gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, std::less<double>)#1}>(__pstl::execution::v1::parallel_unsequenced_policy const&, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, __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&, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, std::less<double>, std::integral_constant<bool, true> >(__pstl::execution::v1::parallel_unsequenced_policy const&, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, std::less<double>, std::integral_constant<bool, true>, std::integral_constant<bool, true>, std::integral_constant<bool, true>)::{lambda()#1}::operator()() const::{lambda(__gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, std::less<double>)#1}, 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 吗?

clang linker-errors tbb

评论


答:

1赞 Nate Eldredge 6/6/2021 #1

我相信大多数 Linux 发行版上的 clang 都与 GNU libstdc++ 相关联,其支持确实需要 libtbb。这隐藏在文档中,搜索“注释 3”。因此,您必须安装 libtbb 并添加到您的 link 命令中。<execution>-ltbb