project-wide include ....

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In another post about differences between debug and releas-configutrations I read a short passage about a project.h-file.

Unfortunately I did not find any additional information about this, so I am asking now here:

most of my AS 6.1 projects have several source-code-files and tehy all (or most) need a project-wide header-file.

Now, I present this header-file manually with an additional command-line sequence, but I would prefer to set this header-file via GUI.

Maybe there is a mechanism and I did not find it so far.

Maybe project.h can be the solution. The name would tell me, that this header-file is automatically given to weach source-file - correct ?

I program like a man:
COPY CON: > firmware.hex

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can pass

-include "foo.h"

on the compiler invocation so that all files are compiled as if their fist line was a #include of that file.

EDIT: OK it took a bit of fiddling but I just got this to work in AS6. I had a project with two C files that both were doing:

#include "shared.h"

I removed that from the two files then edited the project settings and under AVR/GNU C compiler and under "Miscellaneous" I added "-include ..\shared.h". It took me a while to work out that the "..\" prefix was required but after that it appeared to work just fine.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The '-include ...' stuff is also my solution at the moment.
But I needed to add the complete path, which makes the command line-sequence nearly unreadable.

Wouldn' that be a nice feature for AS ? A "project-wide"-include, GUI-configurable ?

I program like a man:
COPY CON: > firmware.hex

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Another possibility is to pass a preprocessor symbol and to use that for the inclusion.

-DCONFIG=\"my_config.h\"
#include CONFIG

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
But I needed to add the complete path.

I assume that's because the manual:

http://gcc.gnu.org/onlinedocs/gc...

says:

Quote:
-include file
Process file as if #include "file" appeared as the first line of the primary source file. However, the first directory searched for file is the preprocessor's working directory instead of the directory containing the main source file. If not found there, it is searched for in the remainder of the #include "..." search chain as normal.

So presumably using a -I you could arrange for the .h's to be found without needing to embed their paths into the -include themselves?