84

I have the following code in a sample file:

#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"

However, this code is located in various folders within /home/me/development/skia (which includes core/ animator/ images/ ports/ svg/ and a lot more.)

How can I make GCC recognize this path?

2

3 Answers 3

112

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

Sign up to request clarification or add additional context in comments.

6 Comments

Glad to see this answer here. Another point worth mentioning would be that when you have many ".c" source files, it's necessary to specify each and every one of them in the commandline itself. You can't just do something like a -I to specify that all source files are in a certain directory.
If the header is in the same directory as the source, do you need a special include? I can't get my code to compile either way, and I'm not sure what the problem is
According to this answer to a similar question, gcc would not search the subdirectories for the different header files automatically. Instead, pkg-config could produce the proper -I option?
What's the difference between -I and -L?
@EdwinPratt Perhaps you meant to say that -L tells GCC where to look for binary libraries to include (which are specified with -l). And -I tells GCC where to look for header files to include.
|
41

The -I directive does the job:

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

1 Comment

To anyone needing this: it looks like you can include directories with spaces in them with quotes: -I"some path/with spaces".
10

Using environment variable is sometimes more convenient when you do not control the build scripts / process.

For C includes use C_INCLUDE_PATH.

For C++ includes use CPLUS_INCLUDE_PATH.

See this link for other gcc environment variables.

Example usage in 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

Example usage in 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=

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.