获取Ada(与GNAT一起编译)以从当前目录外部导入文件? [英] Get Ada (compiled with GNAT) to import files from outside current directory?

查看:165
本文介绍了获取Ada(与GNAT一起编译)以从当前目录外部导入文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在大学里编程课程的介绍,选择的语言是Ada。我使用Kate进行编码,并使用GNAT 4.6.3进行编译。我们必须为程序使用教师提供的库,例如:

I'm doing an intro to programming course at university, and the language of choice is Ada. I'm coding in Kate and compiling with GNAT 4.6.3. We have to use teacher-provided libraries for our programs, like so:

with foo;
use  foo;

当然,然后是文件 foo.adb 必须与我的源文件包含在同一目录中。由于有多个项目依赖于该库,并且我希望将每个项目保留在其自己的子目录中,因此我必须将库文件复制到每个新项目中。更不用说我的库代码和源代码都在同一目录中。

Of course, then the file foo.adb has to be contained in the same directory as my source file. Since multiple projects depend on this one library, and I like to keep each project in its own subdirectory, I have to copy the library files into each new project. Not to mention have my library code and source code all in the same directory.

那么有什么办法可以解决:

So is there any way to sort of go:

with ../../lib/foo
use ../../lib/foo

我尝试了一下,但发现的只是东西关于编译器选项。我宁愿不必去弄那些,特别是因为只有某些项目将需要这个特定的库,因此将其添加到全局编译器设置中并使编译器无意义地搜索它不做的路径没有意义。

I've tried looking around a bit but all I've found is stuff about compiler options. I'd rather not have to mess around with those, especially because only certain projects are going to be requiring this particular library, so it wouldn't make sense to add it to a global compiler setting and have the compiler pointlessly searching paths it doesn't need to search.

推荐答案

我将通过命令行 gnatmake <使用GNAT Project工具/ code>。

I would use the GNAT Project facility with command-line gnatmake.

我只是举了一个小例子(所以我可以确定我说的是可行的!)。我有3个目录; teacher / 包含教师提供的源,我认为您不想更改并且可能也没有写访问权限, jacks_lib / 包含 teacher.gpr ,它指向 teacher / (您可以在此处放置自己的库代码以及 jack / 包含您的代码 main.adb main.gpr

I just set up a little example (so I can be sure what I say works!). I have 3 directories; teacher/ contains the teacher-provided source, which I assume you won't want to change and may not have write access to anyway, jacks_lib/ contains teacher.gpr which points to teacher/ (you could put your own library code there as well) and jack/ contains your code main.adb and 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上都可以正常工作。

I should add that I'm using GCC 4.7.0 on Mac OS X, but this should work fine with any recent GNAT.

这篇关于获取Ada(与GNAT一起编译)以从当前目录外部导入文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆