gcc -I 选项标志

gcc -I 添加包含头文件的目录。

句法

$ gcc -Idir [options] [source files] [object files] [-o output file]

例子

项目/src/myheader.h:

// myheader.h
#define NUM1 5

 

我的文件.c:

// myfile.c
#include <stdio.h>
#include "myheader.h"
 
void main()
{
    int num = NUM1;
    printf("num=%d\n", num);
}

 

在不包含目录proj/src 的情况下构建myfile.c

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

 

使用包含目录proj/src构建myfile.c

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

 


也可以看看

Advertising

海湾合作委员会
°• CmtoInchesConvert.com •°