代码块、MinGW、Boost 和静态链接问题

发布于 2024-09-19 12:57:14 字数 682 浏览 6 评论 0原文

我正在使用 MinGW 的代码块,并尝试获得一个简单的程序来使用静态链接进行编译。我已经使用这些说明构建了 Boost 库。一切都很顺利,我能够成功编译这个简单的程序(它可以编译,我知道它不起作用,因为它在消息发送到控制台之前退出,但我只想它编译)。

如果我的链接器库中有一个 DLL,它可以正常编译,但是当我使用相同内容的静态 .a 库切换它时,我会得到未定义的引用,例如“对 `_imp___ZN5boost6threadD1Ev'| 的未定义引用”。

我不知道问题是什么,也找不到解决方案。我认为这可能与链接器设置有关,但我找不到有关如何更改它们的信息。我将非常感谢能够提供的任何帮助。

#include <iostream>
#include <boost/thread.hpp>

void myfunction()
{
    std::cout << "this is a thread" << std::endl;
    return;
}

int main()
{
    boost::thread mythread(&myfunction);
    return 0;

}

I am using Code Blocks with MinGW and am trying to get a simple program to compile with static linking. I have built the Boost libraries using these directions. Everything worked out fine and I was able to successfully compile this simple program (it compiles, I know it doesn't work because it exits before the message is sent to the console, but I just want it to compile).

If I have a DLL in my linker libraries, it compiles fine, but when I switch it with the static .a libraries of the same contents, I get undefined references such as "undefined reference to `_imp___ZN5boost6threadD1Ev'|".

I have no idea what the problem is and can't find the solution. I think it might have to do with linker settings but I can't find information on how to change them. I would be extremely grateful for any help that could be provided.

#include <iostream>
#include <boost/thread.hpp>

void myfunction()
{
    std::cout << "this is a thread" << std::endl;
    return;
}

int main()
{
    boost::thread mythread(&myfunction);
    return 0;

}

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

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

发布评论

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

评论(1

故人如初 2024-09-26 12:57:14

这是因为当标头配置为动态链接时尝试静态链接。我在

It's from trying to link statically when the headers are configured for a dynamic link. I explain this for libssh in this question. Poking around in boost/thread/detail/config.hpp makes me think you should #define BOOST_THREAD_USE_LIB, or use the -D flag to do the same.

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