Reputation: 1009
I am learning a tutorial of makefile at there. For Makefile 2, there is the right codes:
CC=gcc
CFLAGS=-I.
hellomake: hellomake.o hellofunc.o
$(CC) -o hellomake hellomake.o hellofunc.o -I.
Why it doesn't work like this:
hellomake: hellomake.o hellofunc.o
gcc -o hellomake hellomake.o hellofunc.o -I.
and below is the error:
hellomake.c:2:10: error: 'hellomake.h' file not found with <angled> include; use
"quotes" instead
#include <hellomake.h>
^~~~~~~~~~~~~
"hellomake.h"
1 error generated.
Upvotes: 0
Views: 193
Reputation: 409166
In the first "working" makefile you use
CFLAGS=-I.
That will be used when compiling the source files into object files, and tells the compiler (and its preporcessor) that the current directory should be added to the list of system header file directories.
The second makefile doesn't do that. The compiler, when creating the object files, have no extra flags. So the compiler will not add the current directory to the directory list.
The -I
option you have in the second makefile is when linking. By that time the object files have already been created (should have been created if there was no errors), and the -I
flag is not used at all by the linker.
Upvotes: 3