Search code examples
multithreadingboostc++-cliclrboost-thread

Boost Threads with CLR


Using Visual Studio 2008 and Boost Libraries 1.46.1 I want to compile and link the following with the /CLR flag:

#include <boost/thread/thread.hpp>
void run() {}
int main(int argc, char *argv[])
{
    boost::thread t(run);   
}

The first error is about a forward-declared dummy-struct in boost::thread. This post works around this by declaring:

namespace boost {
    struct thread::dummy {};
}

Sure, I now can compile, but then I get the linker warning

Warning 1 warning LNK4248: unresolved typeref token (0100001F) for 'boost.detail.win32._SECURITY_ATTRIBUTES'; image may not run

Running the application results in

The application was unable to start correctly (0xc000007b).

None of the suggestions in the previously mentioned forum thread works for me. I have built a static version of the Boost Threads lib, and it runs fine without the /CLR flag. Debug/Release makes no difference. I'm running under Win7 32-bit.

Any hints?


Solution

  • I've already run into this problem, i don't remember where i got this but one workaround is declare "boost.detail.win32._SECURITY_ATTRIBUTES" after including all the boost headers like so.

    namespace boost { 
        namespace detail { 
            namespace win32 { 
                struct _SECURITY_ATTRIBUTES: public ::_SECURITY_ATTRIBUTES {}; 
            };
        };
    }; 
    

    Remove the namespaces if you want everyone to see it.