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 开发者_C百科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?
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.
Angle brackets are used to find a header in the implicit header paths. Headers in explicit paths, including the current directory, need quotes.
#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
#include "colors.h"
精彩评论