[Mono-list] Unmanaged C++ library

Chris Howie cdhowie at gmail.com
Thu Nov 26 06:01:00 EST 2009


Mario:

To provide a bit more information, the reason you cannot simply
P/Invoke a C++ library is chiefly because every C++ compiler under the
sun uses a different name mangling scheme for method overloads.  For a
system where every library is compiled with the same compiler (like
gcc on Linux) this is not too much of a problem.  But try writing a
runtime that is capable of targeting every known C++ name mangling
scheme -- not fun, and not simple.  Pretty much every C compiler at
this point uses the same name-mangling scheme: none at all.

So, what Alan is saying is that you need to write (or have SWIG write
for you) a C library that simply proxies calls to the C++ library.
This wrapper can be used directly from Mono.

On Wed, Nov 25, 2009 at 9:00 AM, Alan McGovern <alan.mcgovern at gmail.com> wrote:
> You should look into using SWIG to generate a C wrapper around your C++
> library. Then you can just P/Invoke that.
>
> Alan.
>
> On Wed, Nov 25, 2009 at 1:09 PM, Alex Shulgin
> <alexander.shulgin at yessoftware.com> wrote:
>>
>> Mario De Clippeleir wrote:
>> > Hi,
>> >
>> > I was wondering about using a native unmanaged c++ library (DLL on
>> > windows and dylib on mac). How can i accomplish this ?
>> >
>> > After reading http://www.mono-project.com/Interop_with_Natiregister ECX.
>> > Other parameters are pushed onve_Libraries I still was kind of lost.
>> > I cannot change the callingconvention to extern "C" and since it is
>> > quite a large library, using the DLlimport. entrypoint field seems like a
>> > huge task.
>>
>> Take a look at CallingConvention Enumeration here:
>>
>> http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.callingconvention.aspx
>>
>> > So after some more investigation, the only solution i can think of is to
>> > write a C++/CLI wrapper around the native C++ library, so that all methods
>> > and classes are available from within .NET.
>> >
>> > Is this really the only option ? Am i missing something ? Any better
>> > solutions ???
>>
>> No managed C++ won't work with Mono -- only with .Net.
>>
>> --
>> Alex
>>
>> _______________________________________________
>> Mono-list maillist  -  Mono-list at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/mono-list
>
>
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>
>



-- 
Chris Howie
http://www.chrishowie.com
http://en.wikipedia.org/wiki/User:Crazycomputers


More information about the Mono-list mailing list