[Mono-osx] Problem building and using a Cocoa .dylib

Uli Hertlein uli at xdt.com.au
Mon Feb 6 23:00:07 UTC 2012


On 7/02/2012 05:51, tlapse wrote:
> Ok, I tried a simple c++ library and I get the same error.
>
> [DllImport("liblibqlrtx.dylib", EntryPoint = "myreverse", SetLastError =
> true, CallingConvention = CallingConvention.Cdecl)]
> static extern int myreverse([MarshalAs(UnmanagedType.LPArray)] byte[] key);
>
> "System.EntryPointNotFoundException:"
>
>
> ---- the .h file
> #ifndef libqlrtx_libqlrtx_h
> #define libqlrtx_libqlrtx_h
>
> extern "C" void myreverse(char s[]);
>
> #endif
>
> ---- the .cpp file
> #include<iostream>
>
> /* reverse:  reverse string s in place */
> void myreverse(char s[])
> {
>      int i, j;
>      char c;
> 	
>      for (i = 0, j = strlen(s)-1; i<j; i++, j--) {
>          c = s[i];
>          s[i] = s[j];
>          s[j] = c;
>      }
> }

Looks like you're not actually including the .h file in the 
implementation.  (Or is it just a typo?)

If you don't include it then compiler never sees the 'extern "C"' part 
and the 'myreverse' function will be name mangled as any C++ function.

Cheers,
/uli


More information about the Mono-osx mailing list