You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在GPR项目文件中指定可执行文件名?能否输出到上级目录?

How to specify output executable name and parent-directory path in a GNAT GPR project?

I'm working with an Ada project using GNAT's GPR build system, and I need to customize where my executable ends up and what it's named. My current project file looks like this:

project some_project is
   for Source_Dirs use ("src");
   for Object_Dir use ("obj");
   for Main use ("main.adb");
   package Compiler is
      for Default_Switches ("ada") use ("-O1", "-gnatwae");
   end Compiler;
end some_project;

Right now, it generates an executable named main.exe in the project's root directory. I want instead to output ../some_program_name.exe — so changing both the executable's name and sending it to the parent directory. How do I configure this in the GPR file?


Answer

Great question! You can handle both requirements directly in your GPR project file using two key attributes: Executable_Name and Executable_Dir. Here's the updated project code that does exactly what you need:

project some_project is
   for Source_Dirs use ("src");
   for Object_Dir use ("obj");
   for Main use ("main.adb");
   -- Send the executable to the parent directory
   for Executable_Dir use "../";
   -- Set a custom name for the executable
   for Executable_Name use "some_program_name";
   package Compiler is
      for Default_Switches ("ada") use ("-O1", "-gnatwae");
   end Compiler;
end some_project;

Let me break down each part:

  • Executable_Dir: This attribute defines the output directory for your final executable. Using "../" tells GNAT to place the file in the directory one level above your project file's location.
  • Executable_Name: This overrides the default executable name (which is normally the base name of your Main file — so main in this case). Setting it to "some_program_name" will produce some_program_name.exe on Windows (or just some_program_name on Unix-like systems).

You can also use these attributes independently if you only need one of the changes:

  • If you just want a custom name but keep the executable in the default location, skip the Executable_Dir line.
  • If you just want to move the default-named executable to the parent directory, only include the Executable_Dir line.

One quick heads-up: Make sure the parent directory exists before building. GNAT won't create it automatically, so you'll need to make it manually or add a post-build step if you want it created dynamically.

内容的提问来源于stack exchange,提问作者TamaMcGlinn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 11:42:32