Click here to Skip to main content
15,844,477 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I've been trying to P/Invoke a *.framework file on a mac with C# but always get a DllNotFoundException.
I tried to follow this guide but no luck.

The .framwork file is in a subfolder right beside the application.
The config file looks like this:
XML
<configuration>
   <dllmap dll="MacLib" target="Subfolder/Lib.framework" />
</configuration>

and the P/Invoke code:
C#
[DllImport("MacLib")]
private static extern void SomeMethod();

I know about the case sensitivity on mac, so that's not the problem.
I also tried to put the .framework file into the mac framworks folder but that didn't work either.

I'm not very experienced with mono on mac so I might overlook something obvious.
Hope you can help me out here.

Thank you in advance
Johannes
Posted

1 solution

The best and recommended way is to use this:
C#
[DllImport("@executable_path/../Frameworks/EDSDK.framework/EDSDK")]

The framework files should be in the Frameworks folder and with the DllImport attribute you use standard C# and not some Mono xml-config.

ok I found the problem. There are three ways:

1. framework in the computers /Library/Frameworks/ folder:
Works for libraries as well as apps.
The config file has to look like this:
XML
<configuration>
   <dllmap dll="MacLib" target="Lib.framework/Lib" />
</configuration>


2. framework within the app:
Works only for an app.
The config file has to look like this:
XML
<configuration>
   <dllmap dll="MacLib" target="@executable_path/../Frameworks/Lib.framework/Lib" />
</configuration>

Then you have to put the framework into the *.app. If not there already, create a folder called "Frameworks" in the "Contents" folder and put the .framwork in it.

3. framwork beside the app (or in subfolder beside app):
Works for libraries as well as apps.
The config file has to look like this:
XML
<configuration>
   <dllmap dll="MacLib" target="@executable_path/../../../Lib.framework/Lib" />
</configuration>

If the framework is in a subfolder beside the library/app, change the path accordingly.
e.g. @executable_path/../../../Subfolder/Lib.framework/Lib



Maybe that helps someone else too.
Kind regards
Johannes
 
Share this answer
 
v2
Comments
sumasekar 28-May-15 17:47pm    
Hi,
Can we reference the target lib in other folders apart from the ones mentioned here. For example : /opt/lib/*.dll
Johannes Bildstein 28-May-15 19:13pm    
Hi,
I suppose you can but in the Canon SDK documentation it says that you should not put the library into a system folder.
On page 14 there is also an objective-C snippet to load the library.

btw. the probably easiest way to reference the DLLs/framework is to use:
[DllImport("@executable_path/../Frameworks/EDSDK.framework/EDSDK")]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900