TBB parallel_queue错误 [英] TBB concurrent_queue errors

查看:168
本文介绍了TBB parallel_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

解决方案

您要指定用于链接的库和源/目标文件的顺序很重要. 在此处查看更多详细信息:为什么链接库的顺序有时会导致GCC错误?

在这种情况下,在程序源文件(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 code

concurrent_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.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

解决方案

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 -ltbb

the compilation should succeed.

这篇关于TBB parallel_queue错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆