代码块、MinGW、Boost 和静态链接问题
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为当标头配置为动态链接时尝试静态链接。我在
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.