How to specify default include directory in GCC

2019-09-08 00:17发布

I am new in GCC and I am wondering how to tell the compiler that several include directories need to be specified as default for searching .h files. I read that -I dir is the key to accomplish that but doing my makefiles I encounter some problems. For example:

include_dir = C:/Users/rmrd001/Documents/Make/GCC/first/mydir/
FLAGS = -I "$(include_dir)"

func2.o: func2.c func2.h
    gcc $(FLAGS) -c func2.c

And I got the error:

make:*** No rule to make target 'func2.c', needed by 'func2.o'. Stop.

The include_dir is not the working directory. It is working_directory/my_dir. Please help.

标签: c gcc gnu-make
2条回答
一夜七次
2楼-- · 2019-09-08 00:47
  • You can add path with -I option right in command line;
  • You can specify path with env variable C_INCLUDE_PATH

Also you can find more info on gcc official site and here

查看更多
一纸荒年 Trace。
3楼-- · 2019-09-08 00:52

-I is used for finding include files, but not for finding the main file. You have to pass an explicit path to the main file.

查看更多
登录 后发表回答