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

时间:2009-06-10 00:20:38

标签: c++ gcc header

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

#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 /等等。)

如何让GCC认识到这条道路?

3 个答案:

答案 0 :(得分:69)

试试gcc -c -I/home/me/development/skia sample.c。请参阅here

答案 1 :(得分:23)

-I指令完成工作:

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

答案 2 :(得分:0)

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

对于C包括使用C_INCLUDE_PATH

对于C ++包括使用CPLUS_INCLUDE_PATH

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

在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=