Boost logo

Boost Users :

From: Dan Kelly (dkellyb717_at_[hidden])
Date: 2007-04-02 11:18:06


Thanks for the quick response. It seems your last suggestion holds the most
promise. It appears that I do have a library mismatch problem. I removed
all boost references in a test build, and ran into the same problem with the
initialization of some other non POD, native types. Still don't have this
resolved, but now it looks like I shouldn't continue this thread on this
mailing list.

I'll still take a look at the example you cited.

Dan Kelly

-----Original Message-----
From: John Maddock [mailto:john_at_[hidden]]
Sent: Saturday, March 31, 2007 12:33 PM
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] boost in a mixed CLR assemby

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.


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