Using GNAT DLLs from Microsoft Visual Studio Applications (GNAT User’s Guide for Native Platforms)

#### 7.4.8.24 Using GNAT DLLs from Microsoft Visual Studio Applications ¶

This section describes a common case of mixed GNAT/Microsoft Visual Studio application development, where the main program is developed using MSVS and is linked with a DLL developed using GNAT. You should develop such a mixed application following the general guidelines outlined above; below is the cookbook-style sequence of steps to follow:

1. First develop and build the GNAT shared library using a library project (let’s assume the project is `mylib.gpr`, producing the library `libmylib.dll`):

>     $ gprbuild -p mylib.gpr

2. Produce a `.def` file for the symbols you need to interface with, either by hand or automatically with possibly some manual adjustments (see Creating Definition File Automatically):

>     $ dlltool libmylib.dll -z libmylib.def --export-all-symbols

3. Make sure that MSVS command-line tools are accessible on the path.
4. Create the Microsoft-style import library (see MSVS-Style Import Library):

>     $ lib -machine:IX86 -def:libmylib.def -out:libmylib.lib

If you are using a 64-bit toolchain, the above becomes…

>     $ lib -machine:X64 -def:libmylib.def -out:libmylib.lib

5. Build the C `main`:

>     $ cl /O2 /MD main.c libmylib.lib

6. Before running the executable, make sure you have set the PATH to include the DLL or copy the DLL into into the directory containing the `.exe`.