C# native interop

C code:

 #include <stdio.h>
  
  
 void say_hello_world()
 {
   printf("Hello world from C\n");
 }

Compile the above C code with clang as follows:

clang hello.c -dynamiclib -o libhelloworld.dylib

C# code:

using System.Runtime.InteropServices;

var a = Test.say_hello_world();
class Test
{

    [DllImport("helloworld")]
    public static extern int say_hello_world();
}

Output of C# code:

Hello world from C

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *