2

I have some C++ code that I need to compile using Adacore GNAT Programming Studio.

One file (SomeHeader.h) is in a Common directory (../../Common/) relative to my GPR file.

Our convention for C++ include directives is to use

#include "Common/SomeHeader.h"

No matter what I do, I cannot get GprBuild to find "Common/SomeHeader.h" I followed the instructions here at AdaGem 108 with modifications for C++

for Include_Switches ("c++") use ("-I ../../");

and

for Include_Path ("c++") use "../..";

None of this seems to work for me during gprbuild and frustratingly I can't seem to get at the backend command that gprbuild is using even after turning the build verbosity up.

I see some temp files in the build messages but they get deleted before I can access them.

I am using Adacore GPS 17.1 on Windows 10 i686-pc-mingw32, GNAT Pro 17.1.

Does anyone know how to get include search paths working in Adacore's Gprbuild?

Jacob Sparre Andersen
  • 6,733
  • 17
  • 22
Okkenator
  • 1,654
  • 1
  • 15
  • 27

2 Answers2

3

If you want to use relative paths, and you are dead set on using the -I flag, be aware that the current directory at the time you compile your c++ code it is set to the obj directory configured for grp.

So if the directory you want to include is located at C:\Foo\Bar\src\include\ and your grp obj directory is at C:\Foo\Bar\env\gpr\obj then your relative path will need to use -I..\..\..\src\include

Not Saying
  • 194
  • 11
  • Yes, the level of indirection is one more than for the Source_Dirs since the -I is invoked from the obj dir – Okkenator Nov 15 '18 at 17:48
2

I haven't tried to use gprbuild for compiling C++ source text yet, but I suppose it works more or less like with Ada, where you add the relevant directories to the Source_Dirs attribute:

project Cookie is
   for Languages use ("C++");

   for Source_Dirs use (".",
                        "../..");

   [...]
end Cookie;
Jacob Sparre Andersen
  • 6,733
  • 17
  • 22
  • 1
    The problem is that the Common files are compiled in a separate GPR file that I am withing into this one so I don't want them to be in this one too because I will get duplicate symbols at link time. Maybe I can isolate the header files from the cpp files though and try what you suggested. I'm still not sure if the **Common/SomeHeader.h** will work though. I will try tomorrow morning. – Okkenator Mar 25 '18 at 18:27
  • Then you may need to mark the GPR file for the common files as a `library project`. – Jacob Sparre Andersen Mar 26 '18 at 05:25
  • Does the common files GPR file list the directory containing "SomeHeader.h" in `Source_Dirs`? If that's the case, the solution may be to remove "Common/" from the `include` directive in the C++ source file. – Jacob Sparre Andersen Mar 26 '18 at 05:29
  • Yes the common files GPR has the directory containing SomeHeader.h. – Okkenator Mar 26 '18 at 12:25
  • 2
    I marked this as the answer since the directory at the top level `../..` does not contain any source files. I was able to add that as a source dir in my GPR file even though it does not cause any files to be added to the project. This gives me the ability to have `#include "Common/SomeHeader.h"` in my files – Okkenator Mar 26 '18 at 12:29
  • Thank you for the help @Jacob – Okkenator Mar 26 '18 at 12:30