【发布时间】:2015-03-05 04:24:17
【问题描述】:
我目前正在运行 Ubuntu(最新固件)并且有一堆我为我的 c 编程创建的目录。但是,编译时出现错误,告诉我找不到“file.h”头文件 在我的主文件夹“temp”中 目录如下
temp
然后:
src bin include assets Makefile
src 包含一个 .c 文件,它是:
#include "file.h"
int main(void)
{
initscr();
noecho();
cbreak();
char ch;
FILE * ptr;
ptr = fopen("input.txt","r");
if (ptr == NULL)
{
mvprintw(0,0,"Error reading from file");
exit(1);
}
while( ( ch = fgetc(ptr) ) != EOF )
mvprintw(0,0,"%c",ch);
refresh();
fclose(ptr);
return 0;
}
我的包含文件夹包含头文件(这给了我错误) 这就是 file.h 包含的内容...
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ncurses.h>
我还有一个 makefile 如下:
all:
gcc -Wall -pedantic -std=c99 src/file.c assets/input.txt -o bin/runMe
最后,资产包括一个 .txt 文件“input.txt”,程序只是应该从资产目录中的文本文件中读取一些字符。我试过使用“#include ”表示法,但这似乎没有帮助。我也尝试使用类似“#include”include/file.h“的东西,但也无济于事。
【问题讨论】:
-
-I path/to/your/include/folder在编译器中的任何源文件可能有帮助之前。 -
我已将其更改为:gcc -Wall -pedantic -std=c99 -Iinclude/include src/file.c assets/input.txt -o bin/runMe -lncurses
-
但我仍然遇到同样的错误
-
为什么要添加两个包含目录
include/include?根据您的目录结构,您似乎只想要-Iinclude。您应该使用#include "file.h"语法,而不是#include <file.h>。
标签: c file makefile header ncurses