0

I am porting some C# code we had on Windows to be used on the Mac via Mono. In our code we P\Invoke into a unmanaged C++ dll. Unfortunately the build process we have can only give out a Framework file on the Mac and not a dylib file.

When I ported my code for Mono everything works fine but the P\Invoke into the Framework file. I tried adding out framework file to /Library/Frameworks folder which should be in the default search path but I keep getting a DllNotFound exception. According to the Mono Interop Guide there is an issue with Mono adding .so as the extension to search for on the Mac. So I tried adding a config file and give the target as a .framework file but still I got the same exception. The Mono guide mentions it gets more complicated to do a P\Invoke with Frameworks but doesn't mention the exact issues or how to get around them.

Anybody Know how to P\Invoke into a Framework on Mono?

Shivaprasad
  • 399
  • 2
  • 5
  • 12
  • This issue is solved. The problem was that even though the main Framework itself was found there were other libraries which my framework depended on which were not present on my machine. Once I copied these libraries, the P/Invoke worked fine. – Shivaprasad Oct 08 '12 at 09:44

1 Answers1

0

You can put your framework inside the generated app bundle, see my answer to this question: Setting path of the Native Library for DllImport on Mono for Mac

Also make sure to set the framework's installation directory relative to your application directory (ie. @executable_path/../Frameworks) in XCode's build configuration; see https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPFrameworks/Tasks/CreatingFrameworks.html.

This is especially important when bundling more than one framework - for instance, if if you P/Invoke into some method in A.framework which depends on B.framework.

Community
  • 1
  • 1
Martin Baulig
  • 3,010
  • 1
  • 17
  • 22