TBB concurrent_queue错误

时间:2013-04-19 23:50:44

标签: intel tbb

即使提到concurrent_queue也似乎无法编译程序。

代码包含此

#include <tbb/concurrent_queue.h>

第二,我在代码中的任何地方添加

concurrent_queue<int> tbbqueue;

这是我在编译时遇到的错误。我能够使用任务等编译其他一些与tbb相关的代码,但由于某种原因这不起作用。

    g++ -O3 -Wall -pthread -std=c++11 -ltbb -o tbbqueue.o tbbqueue.cpp 
tbbqueue.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 status
make: *** [tbbqueue.o] Error 1

1 个答案:

答案 0 :(得分:0)

指定用于链接的库和源/目标文件的顺序很重要。 在此处查看更多详细信息:Why does the order in which libraries are linked sometimes cause errors in GCC?

在这种情况下,在程序源文件(-ltbb)之前的命令行中指定了与TBB(tbbqueue.cpp)链接的标志。因此,当链接器处理TBB库时,它看不到使用它的代码,认为它是不必要的,并且考虑了它的所有符号。然后,它看到了从tbbqueue.cpp编译的目标文件中的外部符号,但没有看到可以找到这些符号的库。

如果选项顺序改变如下:

g++ -O3 -Wall -pthread -std=c++11 -o tbbqueue.o tbbqueue.cpp -ltbb

编译应该成功。

相关问题