
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.
I've used Boost compiled to the CLR runtime with a C# frontend. There's an example doing that in the Boost.Sandbox (look under libs/math_functions).
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.
Could the mutex be being used before it's initialised? Remember that static variables are initialised in an unspecified order.
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.
How was the Boost thread lib built? If your code is using the CLR then you would need to build Boost.Threads using the CLR as well I suspect. The easiest way to do that is to add the thread lib sources to a dll CLR project in your IDE and then make sure that BOOST_THREAD_BUILD_DLL is defined in the project settings. HTH, John.