如何在 GCC 搜索路径中包含头文件?

我在一个示例文件中有以下代码:

#include "SkCanvas.h"
#include "SkDevice.h"
#include "SkGLCanvas.h"
#include "SkGraphics.h"
#include "SkImageEncoder.h"
#include "SkPaint.h"
#include "SkPicture.h"
#include "SkStream.h"
#include "SkWindow.h"

但是,这段代码位于/home/me/development/skia (其中包括 core/animator/images/ports/svg/等等)内的各个文件夹中

我怎样才能让海湾合作委员会认识到这条道路?

192872 次浏览

-I指令完成这项工作:

gcc -Icore -Ianimator -Iimages -Ianother_dir -Iyet_another_dir my_file.c

试试 gcc -c -I/home/me/development/skia sample.c

当你不控制构建脚本/过程时,使用环境变量有时会更方便。

对于 C 包括使用 C_INCLUDE_PATH

对于 C + + 包括使用 CPLUS_INCLUDE_PATH

有关其他 gcc 环境变量,请参见此 链接

MacOS/Linux 中的使用示例

# `pip install` will automatically run `gcc` using parameters
# specified in the `asyncpg` package (that I do not control)


C_INCLUDE_PATH=/home/scott/.pyenv/versions/3.7.9/include/python3.7m pip install asyncpg

Windows 中的使用示例

set C_INCLUDE_PATH="C:\Users\Scott\.pyenv\versions\3.7.9\include\python3.7m"


pip install asyncpg


# clear the environment variable so it doesn't affect other builds
set C_INCLUDE_PATH=