Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 733
anve Avatar asked May 23 '11 23:05

anve


People also ask

What is boost thread?

Thread enables the use of multiple threads of execution with shared data in portable C++ code. The Boost. Thread library was originally written and designed by William E.

How do I stop a thread boost?

Interrupting a Thread A running thread can be interrupted by calling the interrupt() member function on the corresponding boost::thread object. If the thread doesn't have a boost::thread object (e.g the initial thread of the application), then it cannot be interrupted.

Does boost use Pthread?

Since boost is mainly just a wrapper around pthreads (on posix platforms) it helps to know what is going on underneath. In attempting to be generic, boost leaves the platform specific functionality unwrapped. In order to get to it you need to use the native_handle() calls.


1 Answers

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.

like image 188
namar0x0309 Avatar answered Sep 22 '22 18:09

namar0x0309