Next: , Previous: , Up: Mixed-Language Programming on Windows   [Contents][Index] 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. Such a mixed application should be developed 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
  1. 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
  1. Make sure that MSVS command-line tools are accessible on the path.
  2. 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
  1. Build the C main
$ cl /O2 /MD main.c libmylib.lib
  1. Before running the executable, make sure you have set the PATH to the DLL, or copy the DLL into into the directory containing the .exe.

Next: , Previous: , Up: Mixed-Language Programming on Windows   [Contents][Index]