简体   繁体   English

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

[英]Code Blocks, MinGW, Boost, and static linking issues

I am using Code Blocks with MinGW and am trying to get a simple program to compile with static linking. 我正在使用MinGW的代码块,我正在尝试使用静态链接编译一个简单的程序。 I have built the Boost libraries using these directions . 我已经使用这些方向构建了Boost库。 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'|". 如果我的链接器库中有一个DLL,它编译得很好,但当我用相同内容的静态.a库切换它时,我得到未定义的引用,例如“未定义引用`_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;

}

It's from trying to link statically when the headers are configured for a dynamic link. 这是在为动态链接配置​​标头时尝试静态链接。 I explain this for libssh in this question . 我在这个问题中为libssh解释了这一点 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. boost/thread/detail/config.hpp进行调查让我觉得你应该#define BOOST_THREAD_USE_LIB ,或者使用-D标志来做同样的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM