我会使用命令行工具
gnatmake
和GNAT项目进行翻译。
我设置了一个小例子(以确保我的说法是正确的!)。我有3个目录:
teacher/
包含老师提供的源代码,我假设你不想更改它,也可能没有写入权限;
jacks_lib/
包含
teacher.gpr
,它指向
teacher/
(你也可以把自己的库代码放在那里);
jack/
包含你的代码
main.adb
和
main.gpr
。
jacks_lib/teacher.gpr
:
project Teacher is
-- This project calls up the teacher-supplied source.
-- This is a list of paths, which can be absolute but
-- if relative are relative to the directory where this .gpr
-- is found.
for Source_Dirs use ("../teacher");
-- Keep the built objects (.ali, .o) out of the way. Use the -p
-- gnatmake flag to have directories like this built
-- automatically.
for Object_Dir use ".build";
end Teacher;
jack/main.gpr
:
-- teacher.gpr tells where to find library source and how to build it.
with "../jacks_lib/teacher";
project Main is
-- for Source_Dirs use ("."); (commented out because it's the default)
-- Keep built objects out of the way
for Object_Dir use ".build";
-- Build executables here rather than in Object_Dir
for Exec_Dir use ".";
-- What's the main program? (there can be more than one)
for Main use ("main.adb");
end Main;
jack/main.adb
:
with Foo;
procedure Main is
begin
null;
end Main;
然后,在
jack/
路径下,
$ gnatmake -p -P main.gpr
object directory "/Users/simon/tmp/jacks_lib/.build" created for project teacher
object directory "/Users/simon/tmp/jack/.build" created for project main
gcc -c -I- -gnatA /Users/simon/tmp/jack/main.adb
gcc -c -I- -gnatA /Users/simon/tmp/teacher/foo.ads
gnatbind -I- -x /Users/simon/tmp/jack/.build/main.ali
gnatlink /Users/simon/tmp/jack/.build/main.ali -o /Users/simon/tmp/jack/main
我应该补充一下,我在Mac OS X上使用的是GCC 4.7.0,但这对于任何近期的GNAT都应该能够正常工作。
("a", "b", "../c")
。 - Simon Wright