3

I'm using a header called colors.h to organize my source code. The header is like this:

#define DEFAULT 0x07
#define BLACK 0
#define GRAY 7
#define BLUE 9
#define GREEN 10
#define CYAN 11
#define RED 12
#define MAGENTA 13
#define YELLOW 14

I'm putting the header at the same directory of the main source code, called kernel.c, and including it like this:

#include <colors.h>

But when I try to compile, I'm getting this:

ubuntu@eeepc:~/Development/Test$ gcc -o kernel.o -c kernel.c -Wall -Wextra -nostdlib -nostartfiles -nodefaultlibs
kernel.c:1:20: error: colors.h: No such file or directory
ubuntu@eeepc:~/Development/Test$

What I can do to solve this?

1

4 Answers 4

18

Use quotes:

#include "colors.h"

Using quotes will look in the same directory first, and then in the specified include paths. Using angle brackets will look in the include paths only.

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

Comments

2

Angle brackets are used to find a header in the implicit header paths. Headers in explicit paths, including the current directory, need quotes.

Comments

1

#include <colors.h> tells GCC to look where it finds the standard C headers, probably not where you have your header. #include "colors.h tells GCC to look for headers in the current working directory

1 Comment

So you want to use the latter in this case
0
#include "colors.h"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.