2013年4月7日 星期日

gcc -I、:=與#include

http://www.rapidtables.com/code/linux/gcc/gcc-i.htm

gcc -I option flag

gcc -I adds include directory of header files.
Syntax
$ gcc -Idir [options] [source files] [object files] [-o output file]
Example
proj/src/myheader.h:

// myfile.h
#define NUM1 5



myfile.c:

// myfile.c
#include
#include "myheader.h"

void main()
{
int num = NUM1;
printf("num=%d\n", num);
}



Build myfile.c without include directory proj/src :

$ gcc myfile.c -o myfile
myfile.c:2:22: fatal error: myheader.h: No such file or directory
compilation terminated.
$



Build myfile.c with include directory proj/src :

$ gcc -Iproj/src myfile.c -o myfile
$ ./myfile
num=5
$


這個方法是可行的,之前的編譯include路徑無效問題出現在
GCC=gcc
LIBFLAGS:=$(CFLAGS) -c
CFLAGS:= -Dxxx -Wall -g -I...
LIBFLAGS使用當下的選項,CFLAGS為空值,從下make指令後可看出。
應該改為:
GCC=gcc
LIBFLAGS=$(CFLAGS) -c
CFLAGS:= -Dxxx -Wall -g -I...

沒有留言:

張貼留言