在 MinGW 下构建/链接到 TBB

发布于 2024-12-26 06:09:04 字数 2259 浏览 1 评论 0原文

我正在 MinGW32(在 Windows 7 64 位上)下构建 TBB 并成功地将一个简单的程序链接到它。不幸的是,我的同事无法成功链接。我们都运行相同版本的 Windows、相同版本的 MinGW (mingw-get-inst-20110802),并尝试编译完全相同的代码。我们的 PATH 环境变量完全相同(.:/usr/local/bin:/mingw/bin:/bin)。然而,尽管所有条件都相同(据我所知),我可以成功构建并运行该程序,但我同事的尝试在链接步骤失败了。如果我给他我的 tbb.dll,那么他就可以成功链接他的程序。因此,我相信他构建的 tbb.dll 有问题。我们已经确认(使用文件)我们正在为所有目标文件和库生成 32 位二进制文​​件

    $ file a.exe
    a.exe: PE32 executable for MS Windows (console) Intel 80386 32-bit
    $ file ./tbb/tbb30_20110704oss/lib/tbb.dll
    ./tbb/tbb30_20110704oss/lib/tbb.dll: PE32 executable for MS Windows (DLL) (console) Intel 80386 32-bit

我们用来构建 TBB 的命令行是:

    mingw32-make compiler=gcc arch=ia32 runtime=mingw tbb

我们正在编译的简单测试程序是:

    #include <tbb/task_scheduler_init.h>
    using namespace tbb;
    int main() {
    task_scheduler_init init;
    return 0;
    }

我们用来构建 TBB 的命令行是 :简单的测试程序

    g++ test1.cpp -I ./tbb/tbb30_20110704oss/include -L ./tbb/tbb30_20110704oss/lib -ltbb

就我而言,它的构建和链接完美无缺。在他的例子中,他收到错误消息:

    test1.o: In function `tbb::task_scheduler_init::task_scheduler_init(int, unsigned int)':
    test1.cpp:(.text._ZN3tbb19task_scheduler_initC1Eij[tbb::task_scheduler_init::task_scheduler_init(int, unsigned int)]+0x33): undefined reference to `tbb::task_scheduler_init::initialize(int, unsigned int)'
    test1.o: In function `tbb::task_scheduler_init::~task_scheduler_init()':
    test1.cpp:(.text._ZN3tbb19task_scheduler_initD1Ev[tbb::task_scheduler_init::~task_scheduler_init()]+0x16): undefined reference to `tbb::task_scheduler_init::terminate()'

该消息似乎表明链接器在查找符号 tbb::task_scheduler_init::initialize() 和 tbb_task_schedule_init::terminate() 时遇到问题。然而,这两个符号都存在于 tbb.dll 中(下面的 nm 输出对于他和我来说都是相同的):

    $ nm ../tbb/tbb30_20110704oss/lib/tbb.dll | grep task_scheduler_init
    676c9cb8 T __ZN3tbb19task_scheduler_init10initializeEi
    676c9c2c T __ZN3tbb19task_scheduler_init10initializeEij
    676c9b64 T __ZN3tbb19task_scheduler_init19default_num_threadsEv
    676c9afc T __ZN3tbb19task_scheduler_init9terminateEv

任何人都可以提供任何建议,解释为什么当我的同事无法链接时我能够构建和链接这个简单的示例,尽管我们使用的是相同的工具、二进制文件、源代码、操作系统等?

I am building TBB under MinGW32 (on Windows 7 64 bit) and linking a simple program to it successfully. Unfortunately, my colleague is unable to do link successfully. We are both running the same version of Windows, the same version of MinGW (mingw-get-inst-20110802), and atttempting to compile the exact same code. Our PATH environment variable is exactly the same (.:/usr/local/bin:/mingw/bin:/bin). Yet, despite all things being equal (as far as I can tell), I can successfully build and run the program, my colleages attempts have failed at the link step. If I give him my tbb.dll, then he can successfully link his program. Thus, I am led to believe that there is something wrong about his build of tbb.dll. We have confirmed (using file) that we are producing 32-bit binaries for all object files and libraries

    $ file a.exe
    a.exe: PE32 executable for MS Windows (console) Intel 80386 32-bit
    $ file ./tbb/tbb30_20110704oss/lib/tbb.dll
    ./tbb/tbb30_20110704oss/lib/tbb.dll: PE32 executable for MS Windows (DLL) (console) Intel 80386 32-bit

The command line we are using to build TBB is:

    mingw32-make compiler=gcc arch=ia32 runtime=mingw tbb

The simple test program we are compiling is:

    #include <tbb/task_scheduler_init.h>
    using namespace tbb;
    int main() {
    task_scheduler_init init;
    return 0;
    }

The command line we are using to build the simple test program

    g++ test1.cpp -I ./tbb/tbb30_20110704oss/include -L ./tbb/tbb30_20110704oss/lib -ltbb

In my case, it builds and links flawlessly. In his case, he gets the error message:

    test1.o: In function `tbb::task_scheduler_init::task_scheduler_init(int, unsigned int)':
    test1.cpp:(.text._ZN3tbb19task_scheduler_initC1Eij[tbb::task_scheduler_init::task_scheduler_init(int, unsigned int)]+0x33): undefined reference to `tbb::task_scheduler_init::initialize(int, unsigned int)'
    test1.o: In function `tbb::task_scheduler_init::~task_scheduler_init()':
    test1.cpp:(.text._ZN3tbb19task_scheduler_initD1Ev[tbb::task_scheduler_init::~task_scheduler_init()]+0x16): undefined reference to `tbb::task_scheduler_init::terminate()'

The message seems to indicate that the linker is having a problem finding the symbols tbb::task_scheduler_init::initialize() and tbb_task_schedule_init::terminate(). However both of these symbols exist in tbb.dll (the nm output below is identical for both him and I):

    $ nm ../tbb/tbb30_20110704oss/lib/tbb.dll | grep task_scheduler_init
    676c9cb8 T __ZN3tbb19task_scheduler_init10initializeEi
    676c9c2c T __ZN3tbb19task_scheduler_init10initializeEij
    676c9b64 T __ZN3tbb19task_scheduler_init19default_num_threadsEv
    676c9afc T __ZN3tbb19task_scheduler_init9terminateEv

Can anyone offer any suggestion as to why I would be able to build and link this simple example, when my colleague cannot link, despite the fact that we are using the same exact tools, binaries, source code, operating system, etc??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离笑几人歌 2025-01-02 06:09:04

解决了。这似乎是 MinGW 的缺陷,特别是 ld.exe。从 ld 版本 2.21.1 恢复到 ld 版本 2.21 可以解决该问题。我和我的同事使用不同版本的 ld

SOLVED. This appears to be a defect in MinGW, specifically ld.exe. Reverting from ld version 2.21.1 to ld version 2.21 solves the issue. My colleague and I were using different versions of ld

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文