Boost Threads - x86 Platforms / 64 bits compilation in Managed/Unmanaged Code / Visual Studio 2010 / Windows SDK 7.1 /clr

As I had lots of issues to include boost thread libraries in a windows 64 bits code generated under Visual Studio 2010, here are the different steps to follow in order to get it compiling and executing quickly (mix of lots of the different specific posts). I could not find an easy, up to date procedure for this. This has been tested with Boost 1_49_0 release, Visual Studio 2010, Windows SDK 7.1 and Microsoft .NET 4. - Download 64 bits libraries, as binaries: http://boost.teeks99.com/ + unzip in a dedicated folder (for the example C:\boost\lib64) - Download boost headers and source code: http://sourceforge.net/projects/boost/files/boost/1.49.0/ + unzip in a dedicate folder (for the example C:\boost) - Set the project not to use precompiled headers + compilation with /clr to mix managed and unmanaged code - Add the headers path to the project additional include directories (in the example C:\boost) - Add the compiled libraries path to the linker additional library directories (in the example C:\boost\lib64) - Add to your project the following lines (force dynamic linking): #define BOOST_ALL_DYN_LINK #define BOOST_THREAD_USE_DLL #define BOOST_LIB_DIAGNOSTIC #include <boost/thread.hpp> --> Just compile and execute, it should not give any problems. The first line (#define BOOST_ALL_DYN_LINK) solves the following error I had: An unhandled exception of type 'System.TypeInitializationException' occurred in Unknown Module. Additional information: The type initializer for '<Module>' threw an exception.

On 05/07/2012 01:28 PM, Guillaume Rembert wrote:
As I had lots of issues to include boost thread libraries in a windows 64 bits code generated under Visual Studio 2010, here are the different steps to follow in order to get it compiling and executing quickly. [...]
Let me point out those are fairly normal steps to get any C++ library to work with any C++ compiler. There is nothing special here.
- Add to your project the following lines (force dynamic linking): #define BOOST_ALL_DYN_LINK
This sets all Boost libraries to use their dynamic variant. Indeed, the headers need to know whether you want to link against the static or dynamic variant of the libraries (especially on Windows, on most other platforms this doesn't really matter).
#define BOOST_THREAD_USE_DLL
This sets Boost.Thread to use its dynamic variant. There is also BOOST_THREAD_DYN_LINK that does essentially the same thing. I don't know why Boost.Thread has two of them, probably historical reasons. Note BOOST_ALL_DYN_LINK does imply BOOST_THREAD_DYN_LINK.
#define BOOST_LIB_DIAGNOSTIC
This is an option to debug your setup, and is not necessary.
#include<boost/thread.hpp>
You should probably define those flags on the command line, not before including <boost/thread.hpp>.
participants (2)
-
Guillaume Rembert
-
Mathias Gaunard