Importing C library into Xamarin console project -


so have simple project possible. entire thing looks like:

enter image description here

main.c

#include "main.h" int testdejef(int i) {     return i+1; } 

main.h

#ifndef __main_h__ #define __main_h__  int testdejef(int i); #endif 

program.cs

using system; using system.runtime.interopservices;   namespace testclib {     class mainclass     {         [dllimport("libclibjef.a",entrypoint="testdejef")]         private static extern int testdejef(int i);          public static void main (string[] args)         {              console.writeline (testdejef (1).tostring ());         }     } } 

based on various xamarin examples on web, seems right. isn't, right compilation causes "system.dllnotfoundexception". note compiling causes no issues, debugger does.

i've read trough pages these: http://developer.xamarin.com/guides/ios/advanced_topics/native_interop/

but documentation seems related android or ios code , issue seems console-application related. knows proper way link c-library project?

update: might harder expected. based on mono documentation:

note: mono uses glib load libraries, , glib has bug on mac os x doesn’t use .dylib extension, instead uses unix .so extension. while should fixed, current workaround write .config file maps .dylib file

as far know, console applications dont have app.config file instead compiled .so .dylib @ moment i'm stuck @ point. mono page says files should linked in library lookup folders. did add folder of suggested environment variables did nothign me

this easy, you're not doing entirely correct. problem need dynamic library (libclibjef.dylib), , use in dllimport attribute.

it's unclear whether you're building dynamic library or static library (libclibjef.a - notice extension), in dllimport you're referencing static library.

the correct dllimport attribute looks this:

[dllimport ("libclibjef.dylib")] 

and make sure have dynamic library next executable.

if still have problems, can run program terminal this:

export mono_log_level=debug export mono_log_mask=dll mono --debug yourapp.exe 

and you'll debug output explaining what's going on.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -