gcc -I dodaje katalog dołączania plików nagłówkowych.
$ gcc -Idir [options] [source files] [object files] [-o output file]
proj/źródło/mójnagłówek.h:
// myheader.h
#define NUM1 5
mój plik.c:
// myfile.c
#include <stdio.h>
#include "myheader.h"
void main()
{
int num = NUM1;
printf("num=%d\n", num);
}
Zbuduj myfile.c bez katalogu dołączania proj/src :
$ gcc myfile.c -o myfile
myfile.c:2:22: fatal error: myheader.h: No such file or directory
compilation terminated.
$
Zbuduj myfile.c z dołączonym katalogiem proj/src :
$ gcc -Iproj/src myfile.c -o myfile
$ ./myfile
num=5
$