-1

I don't want to use -I flags each time for including a header file I made before. I want to specify a directory and save header files there and make GNU gcc search there by default.

PS: I use windows and GNU 5.1.0.

Jens
  • 69,818
  • 15
  • 125
  • 179
  • 4
    That's a bad idea. Do what everyone else does, use some build system (in the simplest case a `Makefile` where you define e.g. an `INCLUDES` variable). –  Apr 03 '18 at 11:32
  • 2
    …and please spell properly. – Jens Apr 03 '18 at 11:32
  • You told what you do and what you don't want to do. Mind to ask a question? Best one which is not already covered by the Fine Manual? – too honest for this site Apr 03 '18 at 13:57

2 Answers2

0

because of my low reputation I couldn't add comment, I think you can use your own make file learning from this link:

http://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/

or this:

https://www.cs.oberlin.edu/~kuperman/help/make.html

or write your own script.

samini
  • 195
  • 11
  • 2
    Maybe you can give a brief example on how to solve the problem in make. Then I would be tempted to give you an upvote. – Kami Kaze Apr 03 '18 at 12:20
0

If all your header files are stored in the same directory, you need not include each .h file using -I option. You can do something like

$(GCC) $(CFLAGS) -I$(HDR_INC_PATH) -c <source files>

where HDR_INC_PATH contains the path where your headers are stored.

If you have headers located in multiple locations, you can do something like

HDR_INC_PATH := -I<path1> \
                 -I<path2> \
                 -I<path3> \
                  and so on

where path1, path2 and path3 are the locations where the headers are located and use

$(GCC) $(CFLAGS) $(HDR_INC_PATH) -c <source files>

You can also make use of $(wildcard pattern) to search for all the header files in a directory. In this case you have to mention the top directory path so that headers in child directories are also taken. Something like

HDR_FILES = $(wildcard <dir>/*.h)

where dir is the path of your parent directory. You can then make use $(HDR_FILES) with -I in your compiler recipe.