2010-01-26 46 views
3

我正在使用名爲colors.h的標題來組織我的源代碼。標題是這樣的:gcc找不到包含的標題

#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 

我把標題在主源代碼的同一目錄下,名爲kernel.c,以及包括像這樣:

#include <colors.h> 

但是,當我嘗試編譯,我得到這個:

[email protected]:~/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
[email protected]:~/Development/Test$

我能做些什麼來解決這個問題?

+0

其他很多其他的http://stackoverflow.com/questions/973146/how-to-include-header-files-in-gcc-search-path。 – 2010-01-26 14:22:13

+1

顏色拼寫錯誤。 – 2010-01-26 14:23:22

+0

lol @ colors拼錯了 – JonH 2010-01-26 14:50:06

回答

18

使用引號:

#include "colors.h" 

使用引號將尋找在同一個目錄,然後再在指定的include路徑。 使用尖括號只會查看包含路徑。

0
#include "colors.h" 
2

尖括號用於在隱式標題路徑中查找標題。顯式路徑中的標題包括當前目錄需要引號。

1

#include <colors.h>告訴海灣合作委員會看看它在哪裏找到標準的C頭,可能沒有你的頭。 #include "colors.h告訴GCC在當前工作目錄中查找標題

+0

所以你想在這種情況下使用後者 – theunamedguy 2013-04-02 15:29:28