126.96.36.199 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:
- 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):
- 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
- Make sure that MSVS command-line tools are accessible on the path.
- 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
- Build the C main
$ cl /O2 /MD main.c libmylib.lib
- 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.