如何链接MinGW(gcc)和TBB [英] How to link MinGW (gcc) and TBB

查看:153
本文介绍了如何链接MinGW(gcc)和TBB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用MinGW编译我的TBB程序.我知道TBB已正确安装在我的计算机上,因为它可以在Visual Studio中正常编译.我是否还需要告诉MinGW TBB的安装位置?还是只是链接库就足够了?尝试使用gcc进行编译时,出现这些错误.

I am trying to compile my TBB program using MinGW. I know that TBB is installed on my machine correctly because it compiles just fine in Visual Studio. Do I have to do something more to tell MinGW where TBB is installed? Or is just linking the library all that is needed? I am getting these error, when trying to compile using gcc.

 C:\Users\Owner\Desktop\New folder\OpenMP vs TBB>make
g++  -LC:\tbb\tbb\lib\intel64\vc14 -O3 -o pps avl.o main.o parPlaneSweep.o -fopenmp -ltbb
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x433f): undefined reference to `tbb::task_group_context::init()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x435d): undefined reference to `tbb::internal::allocate_root_with_context_proxy::allocate(unsigned int) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x439d): undefined reference to `tbb::internal::get_initial_auto_partitioner_divisor()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x43d0): undefined reference to `tbb::task_group_context::~task_group_context()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x47d5): undefined reference to `tbb::task_group_context::init()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x47f3): undefined reference to `tbb::internal::allocate_root_with_context_proxy::allocate(unsigned int) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x4835): undefined reference to `tbb::internal::get_initial_auto_partitioner_divisor()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x4868): undefined reference to `tbb::task_group_context::~task_group_context()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x7743): undefined reference to `tbb::internal::allocate_continuation_proxy::allocate(unsigned int) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x776c): undefined reference to `tbb::internal::allocate_child_proxy::allocate(unsigned int) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x7a66): undefined reference to `tbb::task_group_context::is_group_execution_cancelled() const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x7abc): undefined reference to `tbb::internal::allocate_continuation_proxy::allocate(unsigned int) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x7ae5): undefined reference to `tbb::internal::allocate_child_proxy::allocate(unsigned int) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x8cab): undefined reference to `tbb::internal::allocate_continuation_proxy::allocate(unsigned int) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x8cd4): undefined reference to `tbb::internal::allocate_child_proxy::allocate(unsigned int) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x8f69): undefined reference to `tbb::task_group_context::is_group_execution_cancelled() const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x8fb4): undefined reference to `tbb::internal::allocate_continuation_proxy::allocate(unsigned int) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x8fdd): undefined reference to `tbb::internal::allocate_child_proxy::allocate(unsigned int) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD1Ev[__ZN3tbb4flow11interface105graphD1Ev]+0x43): undefined reference to `tbb::interface7::internal::task_arena_base::internal_execute(tbb::interface7::internal::delegate_base&) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD1Ev[__ZN3tbb4flow11interface105graphD1Ev]+0x4e): undefined reference to `tbb::task_group_context::is_group_execution_cancelled() const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD1Ev[__ZN3tbb4flow11interface105graphD1Ev]+0x73): undefined reference to `tbb::interface5::internal::task_base::destroy(tbb::task&)'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD1Ev[__ZN3tbb4flow11interface105graphD1Ev]+0x87): undefined reference to `tbb::task_group_context::~task_group_context()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD1Ev[__ZN3tbb4flow11interface105graphD1Ev]+0xe3): undefined reference to `tbb::interface7::internal::task_arena_base::internal_terminate()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD1Ev[__ZN3tbb4flow11interface105graphD1Ev]+0xf1): undefined reference to `tbb::task_group_context::reset()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD1Ev[__ZN3tbb4flow11interface105graphD1Ev]+0x10b): undefined reference to `tbb::interface7::internal::task_arena_base::internal_initialize()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD1Ev[__ZN3tbb4flow11interface105graphD1Ev]+0x12e): undefined reference to `tbb::task_group_context::reset()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD0Ev[__ZN3tbb4flow11interface105graphD0Ev]+0x44): undefined reference to `tbb::interface7::internal::task_arena_base::internal_execute(tbb::interface7::internal::delegate_base&) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD0Ev[__ZN3tbb4flow11interface105graphD0Ev]+0x4f): undefined reference to `tbb::task_group_context::is_group_execution_cancelled() const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD0Ev[__ZN3tbb4flow11interface105graphD0Ev]+0x74): undefined reference to `tbb::interface5::internal::task_base::destroy(tbb::task&)'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD0Ev[__ZN3tbb4flow11interface105graphD0Ev]+0x88): undefined reference to `tbb::task_group_context::~task_group_context()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD0Ev[__ZN3tbb4flow11interface105graphD0Ev]+0xf3): undefined reference to `tbb::interface7::internal::task_arena_base::internal_terminate()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD0Ev[__ZN3tbb4flow11interface105graphD0Ev]+0x101): undefined reference to `tbb::task_group_context::reset()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD0Ev[__ZN3tbb4flow11interface105graphD0Ev]+0x11b): undefined reference to `tbb::interface7::internal::task_arena_base::internal_initialize()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD0Ev[__ZN3tbb4flow11interface105graphD0Ev]+0x13e): undefined reference to `tbb::task_group_context::reset()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text.unlikely+0xf3): undefined reference to `tbb::internal::allocate_root_with_context_proxy::free(tbb::task&) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text.unlikely+0xff): undefined reference to `tbb::task_group_context::~task_group_context()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text.unlikely+0x118): undefined reference to `tbb::internal::allocate_root_with_context_proxy::free(tbb::task&) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.rdata$_ZTVN3tbb10interface98internal9flag_taskE[__ZTVN3tbb10interface98internal9flag_taskE]+0x14): undefined reference to `tbb::task::note_affinity(unsigned short)'
collect2.exe: error: ld returned 1 exit status
Makefile:10: recipe for target 'pps' failed
make: *** [pps] Error 1

这是我当前的Makefile现在的样子.

This is what my current Makefile looks like right now.

CC=gcc
CPLUSPLUS = g++ 
OPTFLAGS = -O3
TBB_INCLUDE_PATH = C:\tbb-2020.1-win\tbb\include
TBB_LIBRARY_PATH = C:\tbb\tbb\lib\intel64\vc14

all: pps

pps: avl.o main.o parPlaneSweep.o
    $(CPLUSPLUS) -L$(TBB_LIBRARY_PATH) $(OPTFLAGS) -o $@ $^ -fopenmp -ltbb

avl.o: avl.h avl.c
    $(CC) -c $(OPTFLAGS) -fPIC avl.c

main.o: main.cpp parPlaneSweep.h
    $(CPLUSPLUS) -c $(OPTFLAGS) -fopenmp main.cpp 

parPlaneSweep.o: parPlaneSweep.h parPlaneSweep.cpp
    $(CPLUSPLUS) -c $(OPTFLAGS) -ITBB_INCLUDE_PATH -fPIC -fopenmp parPlaneSweep.cpp

clean:
    rm *.o
    rm pps

推荐答案

MinGW和MSVC是不同的工具链,即使它们都可以生成本机" Windows格式的EXE/DLL文件.但是C ++符号修饰(也称为mangling)的完成方式非常不同,因此源代码中的相同函数将被编译为名称不同的二进制函数.工具链之间可能还会有更多的应用程序二进制接口(ABI)差异.因此,您不能简单地链接由MinGW/为MinGW和MSVC//创建的目标文件/库;您需要使用相同的工具链准备所有库.

MinGW and MSVC are different toolchains, even though both can produce EXE/DLL files in "native" Windows format. But the C++ symbol decoration (aka mangling) is done very differently, so the same function in source code would be compiled into differently named binary functions. There might also be more application binary interface (ABI) differences between the toolchains. Therefore you cannot simply link object files/libraries created by/for MinGW and by/for MSVC; you need all libraries to be prepared with the same toolchain.

您可以自己为MinGW构建TBB二进制文件(TBB makefile支持),也可以尝试找到一个易于使用的软件包,例如问题注释中提到的MSYS2软件包.

You can build TBB binaries for MinGW on your own (it's supported in TBB makefiles), or you can try finding a ready-to-use package such as the one for MSYS2 mentioned in the comments to the question.

这篇关于如何链接MinGW(gcc)和TBB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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