在这种情况下,在程序源文件(tbbqueue.cpp)之前的命令行中指定了与TBB(-ltbb)链接的标志.因此,当链接程序处理TBB库时,没有看到使用它的代码,认为它是不必要的,并从考虑中删除了所有符号.然后,它看到从tbbqueue.cpp编译的目标文件中的外部符号,但找不到可以找到这些符号的库.如果选项顺序更改如下:g++ -O3 -Wall -pthread -std=c++11 -o tbbqueue.o tbbqueue.cpp -ltbb编译应该成功.Can't seem to compile program with even a mention of concurrent_queue.code contains this#include <tbb/concurrent_queue.h>And second I add anywhere in the codeconcurrent_queue<int> tbbqueue;This is the error I get on compile. I am able to compile some other tbb related code using tasks etc, but this for some reason is not working. g++ -O3 -Wall -pthread -std=c++11 -ltbb -o tbbqueue.o tbbqueue.cpptbbqueue.cpp: In function ‘void* Agent(void*)’:tbbqueue.cpp:46:10: warning: unused variable ‘elements’ [-Wunused-variable]tbbqueue.cpp:47:9: warning: unused variable ‘elementsSize’ [-Wunused-variable]/tmp/ccQg8OKZ.o: In function `tbb::strict_ppl::internal::concurrent_queue_base_v3<int>::~concurrent_queue_base_v3()':tbbqueue.cpp:(.text._ZN3tbb10strict_ppl8internal24concurrent_queue_base_v3IiED2Ev[_ZN3tbb10strict_ppl8internal24concurrent_queue_base_v3IiED5Ev]+0x10): undefined reference to `tbb::internal::NFS_Free(void*)'/tmp/ccQg8OKZ.o: In function `tbb::strict_ppl::concurrent_queue<int, tbb::cache_aligned_allocator<int> >::deallocate_block(void*, unsigned long)':tbbqueue.cpp:(.text._ZN3tbb10strict_ppl16concurrent_queueIiNS_23cache_aligned_allocatorIiEEE16deallocate_blockEPvm[_ZN3tbb10strict_ppl16concurrent_queueIiNS_23cache_aligned_allocatorIiEEE16deallocate_blockEPvm]+0x4): undefined reference to `tbb::internal::NFS_Free(void*)'/tmp/ccQg8OKZ.o: In function `tbb::strict_ppl::concurrent_queue<int, tbb::cache_aligned_allocator<int> >::allocate_block(unsigned long)':tbbqueue.cpp:(.text._ZN3tbb10strict_ppl16concurrent_queueIiNS_23cache_aligned_allocatorIiEEE14allocate_blockEm[_ZN3tbb10strict_ppl16concurrent_queueIiNS_23cache_aligned_allocatorIiEEE14allocate_blockEm]+0xf): undefined reference to `tbb::internal::NFS_Allocate(unsigned long, unsigned long, void*)'tbbqueue.cpp:(.text._ZN3tbb10strict_ppl16concurrent_queueIiNS_23cache_aligned_allocatorIiEEE14allocate_blockEm[_ZN3tbb10strict_ppl16concurrent_queueIiNS_23cache_aligned_allocatorIiEEE14allocate_blockEm]+0x2b): undefined reference to `tbb::internal::throw_exception_v4(tbb::internal::exception_id)'/tmp/ccQg8OKZ.o: In function `tbb::strict_ppl::internal::concurrent_queue_base_v3<int>::~concurrent_queue_base_v3()':tbbqueue.cpp:(.text._ZN3tbb10strict_ppl8internal24concurrent_queue_base_v3IiED0Ev[_ZN3tbb10strict_ppl8internal24concurrent_queue_base_v3IiED0Ev]+0x10): undefined reference to `tbb::internal::NFS_Free(void*)'/tmp/ccQg8OKZ.o: In function `tbb::strict_ppl::concurrent_queue<int, tbb::cache_aligned_allocator<int> >::~concurrent_queue()':tbbqueue.cpp:(.text._ZN3tbb10strict_ppl16concurrent_queueIiNS_23cache_aligned_allocatorIiEEED2Ev[_ZN3tbb10strict_ppl16concurrent_queueIiNS_23cache_aligned_allocatorIiEEED5Ev]+0x12d): undefined reference to `tbb::internal::NFS_Free(void*)'/tmp/ccQg8OKZ.o: In function `tbb::strict_ppl::concurrent_queue<int, tbb::cache_aligned_allocator<int> >::~concurrent_queue()':tbbqueue.cpp:(.text._ZN3tbb10strict_ppl16concurrent_queueIiNS_23cache_aligned_allocatorIiEEED0Ev[_ZN3tbb10strict_ppl16concurrent_queueIiNS_23cache_aligned_allocatorIiEEED0Ev]+0x12d): undefined reference to `tbb::internal::NFS_Free(void*)'/tmp/ccQg8OKZ.o: In function `main':tbbqueue.cpp:(.text.startup+0x32): undefined reference to `tbb::internal::NFS_Allocate(unsigned long, unsigned long, void*)'collect2: error: ld returned 1 exit statusmake: *** [tbbqueue.o] Error 1 解决方案 The order, in which you specify libraries and source/object files for linking, matters.See more details here: Why does the order in which libraries are linked sometimes cause errors in GCC?In this case, the flag to link with TBB (-ltbb) was specified in the command line prior to the program source file (tbbqueue.cpp). So when the linker processed the TBB library it had seen no code that uses it, decided it is unnecessary, and removed all its symbols from consideration. Then, it saw external symbols in the object file compiled from tbbqueue.cpp, but not libraries where these symbols could be found.If the order of options is changed like this:g++ -O3 -Wall -pthread -std=c++11 -o tbbqueue.o tbbqueue.cpp -ltbbthe compilation should succeed. 这篇关于TBB parallel_queue错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-25 18:39