Boost logo

Boost Users :

From: John Dunn (john_dunn_at_[hidden])
Date: 2007-05-09 18:44:23


Daniel J. Kelly wrote:
> I realize it is not officially supported, but has anyone had success
> using boost libraries in a mixed CLR assembly? I am using visual studio
> 2005. I have been trying to accomplish this in an applicatation that has
> a Windows Forms front end, whose enire back end is build of libraries
> written in standard C++, making extensive use of boost, especially smart
> pointers and threads.
>
> The specific problem I am having involved initializing static
> variables. For instance, I have a global variable:
> boost::mutex osmutex;
> The program compiles and links fine, but during static initialization, I
> receive an error indicating _CrtIsValidHeapPointer(pUserData) is
> invalid. Looking at the stack unwind, the calling code is the "dynamic
> initializer for 'osmutex'". My suspicion is that the boost library is
> linking to a different run time library than my mixed code, and that the
> pointer being rejected is happening as a result of it coming from a
> different heap.
>
> I would like try to check this hypothesis by building boost forcing it
> to link to the correct C++ runtime library used by mixed assemblies
> (msvcmrtd.dll), but I am not familar enough with the boost build system
> to do this.

Linking to the static version of boost::threads causes problems if you compile
with /clr. I believe this behavior was introduced with Visual Studio 2005 SP1. I
reported the issue both here ( search gmane archive ) and to Microsoft Connect.
Neither party seemed too interested in addressing the issue. A workaround is to
use the dynamic version of boost::threads ( #define BOOST_THREAD_USE_DLL ). Of
course then you have to cart around another DLL but it does appear to fix the
problem.

John


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net