Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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;

}
like image 964
contrapsych Avatar asked Sep 14 '10 01:09

contrapsych


1 Answers

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.

like image 119
Jack Kelly Avatar answered Oct 19 '22 10:10

Jack Kelly