Ada static compilation

Viewed 271

I have compiled a simple Ada application which uses the Win32Ada library.

I'm compiling the application on Windows using:

gnatmake C:\GNAT\2020\bin\src\main.adb -I"C:\GNAT\2020\lib\win32ada" -largs -lwin32ada.

The application works as expected on the compilation machine and when executing main.exe a MessageBox is executed.

However, when attempting to execute the application on another Windows system which doesn't have the Ada libraries installed, I received an error:

The code execution cannot processed because libwin32ada.dll was not found

Does Ada support static compilation?

Can I compile the application so main.exe can execute on any Windows host without needing to bundle DLL's?

I couldn't find an answer in the gnatmake --help (but I'm also new to Ada).

2 Answers

The default linking mode is static on Windows. So, normally, you don't need to add any option. If you need to force it, use the -bargs -static gnatmake binder option or add

 package Binder is
    for Default_Switches ("ada") use ("-static");
 end Binder;

to your .gpr project file.

Does Ada support static compilation?

Yes, it's the default mode.

Can I compile the application so main.exe can execute on any Windows host without needing to bundle DLL's?

You should be able to, but I haven't used the win32ada library much; I would be surprised if you couldn't do something like Deplhi where the executable interfaces with the Win32 API "directly", albeit with the abstraction of the VCL.

I think the item you want to flag is in the Linker, not Binder. (Though you might need both.) The best place to check for the nitty-gritty of arguments for GNAT is the documentation, simply because there's a huge number of arguments which are essentially non-intuitive in their naming or usage.

--unchecked-shared-lib-imports might be of interest; checking out the win32ada project file (especially any scenario variables) might give you the ability to switch it to a static library. In the worst case, if you add For library_kind use "static"; to the Win32Ada library, you should be able to build it statically yourself.

Related