为什么不能编译器找不到头文件? [英] Why can't the compiler find the header file?

查看:957
本文介绍了为什么不能编译器找不到头文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Linux环境中工作。在我的当前目录下,当我执行ls命令,这是我得到了什么

在repo.c,我有这行code的

 的#include< battleship.h>

然而,当我尝试编译,并用这个命令创建可执行文件(也链接库文件battleship.c)

  GCC repo.c -lbattleship.c

我得到这个错误

repo.c:10:24:错误battleship.h:没有这样的文件或目录

有谁知道为什么编译器找不到头文件?我把它放在同一个目录作为主C文件


解决方案

 #包括LT&;>

此变量用于包括系统头文件。

 的#include

此用于包括用户创建的头文件。

所以,请尝试使用

 的#includebattleship.h

I am working in a linux environment. In my current directory, when I performed the ls command, this is what I got

In repo.c, I have this line of code

#include <battleship.h>

However when I try to compile and create the executable with this command(also link to library file battleship.c)

gcc repo.c -lbattleship.c

I get this error

"repo.c:10:24: error battleship.h: No such file or directory"

Does anyone know why the compiler cannot find the header file? I put it in the same directory as the main C file

解决方案

# include<> 

This variant is used to include system header files.

#include ""

This is used to include user created header files.

So try using

#include "battleship.h"

这篇关于为什么不能编译器找不到头文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆