Ada でライブラリを動的および静的にリンクするのに問題があります。最小限の作業例を用意しました。次の 3 つのファイルは、「Hello world」を出力するライブラリを定義します。
helloworld_lib.gpr :
project Helloworld_Lib is
for Library_Name use "helloworld_lib";
for Source_Files use ("helloworld_lib.adb", "helloworld_lib.ads");
for Library_Kind use "static";
for Library_Dir use "obj";
end Helloworld_Lib;
helloworld_lib.adb :
with Ada.Text_IO;
package body helloworld_lib is
procedure Hello is
begin
Ada.Text_IO.Put_Line("Hello world");
end Hello;
end helloworld_lib;
helloworld_lib.ads :
with Ada.Text_IO;
use Ada.Text_IO;
package helloworld_lib is
procedure Hello;
end helloworld_lib;
これら 2 つのファイルは、ライブラリをインポートして実行するプロジェクトを定義します。
helloworld_interface.gpr :
with "helloworld_lib.gpr";
project Helloworld_Interface is
for Create_Missing_Dirs use "True";
for Main use ("helloworld_interface.adb");
for Source_Files use ("helloworld_interface.adb");
for Object_Dir use "obj";
end Helloworld_Interface;
helloworld_interface.adb :
with helloworld_lib; use helloworld_lib;
procedure helloworld_interface is
begin
Hello;
end helloworld_interface;
Windows で GPS 19.1 GNAT Community Edition を使用しています。helloworld_interface.gpr を開いて「Build All」を実行すると、期待どおりに動作し、完全に自己完結型の exe がコンパイルされます。
helloworld_lib.gprでLibrary_Kind
からstatic
に変更し、前と同じようにビルドすると、exe と dll がコンパイルされます。ただし、コンパイルされたファイルは と に依存するようになりました。からコピーできるこれらの DLL がないと、プログラムは実行されません。dynamic
libgnat-2019.dll
libgcc_s_seh-1.dll
C:\GNAT\2019\bin
他の依存関係なしで実行される静的にリンクされた EXE ファイルを生成できる場合、この例を他の依存関係のない EXE および DLL にコンパイルするにはどうすればよいでしょうか? これら 2 つの追加の DLL が必要になったのはなぜですか?