在 Eclipse 上使用 TBB 编译错误

Compilation error with TBB on eclipse

我知道有一个帖子问了类似的问题并且我读了它,但是 我仍然无法解决问题! 这是编译错误:

    13:28:28 **** Rebuild of configuration Debug for project test2 ****
    Info: Internal Builder is used for build
    g++ "-IC:\MinGW\tbb\tbb43_20150611oss\include" -O0 -g3 -Wall -c -fmessage-length=0 -ltbb -std=c++11 -o "src\test2.o" "..\src\test2.cpp" 
    g++ "-IC:\MinGW\tbb\tbb43_20150611oss\include" -O0 -g3 -Wall -c -fmessage-length=0 -ltbb -std=c++11 -o "src\SnipSequence.o" "..\src\SnipSequence.cpp" 
    g++ "-LC:\MinGW\tbb\tbb43_20150611oss\lib" -o test2 "src\test2.o" "src\SnipSequence.o" 
    src\SnipSequence.o: In function `run':
    C:/MinGW/tbb/tbb43_20150611oss/include/tbb/parallel_for.h:90: undefined reference to `tbb::task_group_context::~task_group_context()'
    C:/MinGW/tbb/tbb43_20150611oss/include/tbb/parallel_for.h:90: undefined reference to `tbb::task_group_context::~task_group_context()'
    src\SnipSequence.o: In function `ZN3tbb18task_group_contextC1ENS0_9kind_typeEj':
    C:/MinGW/tbb/tbb43_20150611oss/include/tbb/task.h:450: undefined reference to `tbb::task_group_context::init()'
    src\SnipSequence.o: In function `ZN3tbb4taskC2Ev':
    C:/MinGW/tbb/tbb43_20150611oss/include/tbb/task.h:553: undefined reference to `vtable for tbb::task'
    src\SnipSequence.o: In function `ZN3tbb4taskD2Ev':
    C:/MinGW/tbb/tbb43_20150611oss/include/tbb/task.h:557: undefined reference to `vtable for tbb::task'
    src\SnipSequence.o: In function `ZnwjRKN3tbb8internal32allocate_root_with_context_proxyE':
    C:/MinGW/tbb/tbb43_20150611oss/include/tbb/task.h:998: undefined reference to `tbb::internal::allocate_root_with_context_proxy::allocate(unsigned int) const'
    src\SnipSequence.o: In function `ZdlPvRKN3tbb8internal32allocate_root_with_context_proxyE':
    C:/MinGW/tbb/tbb43_20150611oss/include/tbb/task.h:1002: undefined reference to `tbb::internal::allocate_root_with_context_proxy::free(tbb::task&) const'
    src\SnipSequence.o: In function `ZnwjRKN3tbb8internal27allocate_continuation_proxyE':
    C:/MinGW/tbb/tbb43_20150611oss/include/tbb/task.h:1007: undefined reference to `tbb::internal::allocate_continuation_proxy::allocate(unsigned int) const'
    src\SnipSequence.o: In function `ZdlPvRKN3tbb8internal27allocate_continuation_proxyE':
    C:/MinGW/tbb/tbb43_20150611oss/include/tbb/task.h:1011: undefined reference to `tbb::internal::allocate_continuation_proxy::free(tbb::task&) const'
    src\SnipSequence.o: In function `ZN3tbb10interface78internal16allocate_siblingEPNS_4taskEj':
    C:/MinGW/tbb/tbb43_20150611oss/include/tbb/parallel_for.h:120: undefined reference to `tbb::internal::allocate_child_proxy::allocate(unsigned int) const'
    src\SnipSequence.o:SnipSequence.cpp:(.rdata$_ZTVN3tbb10interface78internal9flag_taskE[__ZTVN3tbb10interface78internal9flag_taskE]+0x14): undefined reference to `tbb::task::note_affinity(unsigned short)'
    collect2.exe: error: ld returned 1 exit status

我在链接器部分和 eclispe 的包含部分尝试了很多东西。我试图更改 -ltbb 和 -std=c++11 的顺序。我仍然无法编译。我敢肯定还有其他人遇到示例问题。

我无法解决我的问题:Whosebug question/answer

Ok 首先在目录中安装一份 MSYS2。在这里找到:https://msys2.github.io/

安装后打开MSYS2的提示符并执行这一行: pacman -S mingw-w64-i686-gcc mingw-w64-i686-make mingw-w64-i686-intel-tbb

然后在MSYS目录文件中搜索gcc.exe,添加到你的系统路径中

在 eclispe 中,在项目属性的 -L 选项中添加 C:\msys64\mingw64\lib,在 -l 选项中添加 tbb,并在 -I 选项中添加 C:\msys64\mingw64\include。

在编译器标志和索引器中添加 -std=c++11 如果你 想要摆脱仅在 Eclipse 中显示的某些错误。瞧!