2

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).

user1220022
  • 11,167
  • 19
  • 41
  • 57
  • why not install the libraries on the second machine? Linking a Windows GUI program statically is likely to produce a rather large executable. –  Jan 13 '21 at 12:59
  • I want to interface with the Windows API, not necessarily create a GUI. MessageBox was just a PoC of interfacing with the API. – user1220022 Jan 13 '21 at 21:56

2 Answers2

1

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.

Zerte
  • 1,478
  • 10
  • 9
  • I forced the `-bargs -static` option, however I still see the same error for the lacking DLL when executing on another host. – user1220022 Jan 13 '21 at 06:44
  • Some configuration in this version of the win32ada library seems to require the DLL. – Zerte Jan 13 '21 at 06:53
  • Side note: if you want to program user interfaces, as your Message Box example seems to suggest, you can use GWindows which is standalone and DLL-less (see https://sourceforge.net/projects/gnavi/ or https://github.com/zertovitch/gwindows ) – Zerte Jan 13 '21 at 07:00
  • I'm trying this on Ubuntu and this just results in a dynamically-linked application. How would this work on Linux? – Julian Stecklina Dec 22 '21 at 11:35
  • Try with `-static` on both gpr packages: Linker *and* Binder. – Zerte Dec 23 '21 at 12:26
0

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.

Shark8
  • 4,095
  • 1
  • 17
  • 31