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?

Nathan Campos
  • 28,769
  • 59
  • 194
  • 300
  • Dupe of http://stackoverflow.com/questions/973146/how-to-include-header-files-in-gcc-search-path among many others. –  Jan 26 '10 at 14:22

4 Answers4

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.

interjay
  • 107,303
  • 21
  • 270
  • 254
2

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

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
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

built1n
  • 1,518
  • 14
  • 25
0
#include "colors.h"
Maurits Rijk
  • 9,789
  • 2
  • 36
  • 53