Getting started with C

Requirements

To use .NET Embedding with C, you'll need a Mac or Windows machine running:

macOS

  • macOS 10.12 (Sierra) or later
  • Xcode 8.3.2 or later
  • Mono

Windows

  • Windows 7, 8, 10 or later
  • Visual Studio 2015 or later

Installing .NET Embedding from NuGet

Follow these instructions to install and configure .NET Embedding for your project.

The command invocation you should configure will look like (possibly with different version numbers and paths):

Visual Studio for Mac

mono {SolutionDir}/packages/Embeddinator-4000.0.4.0.0/tools/Embeddinator-4000.exe --gen=c --outdir=managed_c --platform=macos --compile managed.dll

Visual Studio 2017

$(SolutionDir)\packages\Embeddinator-4000.0.2.0.80\tools\Embeddinator-4000.exe --gen=c --outdir=managed_c --platform=windows --compile managed.dll

Generation

Output files

If all goes well, you will be presented with the following output:

Parsing assemblies...
    Parsed 'managed.dll'
Processing assemblies...
Generating binding code...
    Generated: managed.h
    Generated: managed.c
    Generated: mscorlib.h
    Generated: mscorlib.c
    Generated: embeddinator.h
    Generated: glib.c
    Generated: glib.h
    Generated: mono-support.h
    Generated: mono_embeddinator.c
    Generated: mono_embeddinator.h

Since the --compile flag was passed to the tool, .NET Embedding should also have compiled the output files into a shared library, which you can find next to the generated files, a libmanaged.dylib file on macOS, and managed.dll on Windows.

To consume the shared library, you can include the managed.h C header file, which provides the C declarations corresponding to the respective managed library APIs and link with the previously mentioned compiled shared library.

Further Reading