g ++找不到头文件 [英] g++ cannot find header file

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

问题描述

我从Java迁移到C ++。看来C ++使类声明在单独的文件中,很难。所以我需要你的帮助,

I am migrating from Java to C++. It seems that C++ makes classes declaration in separate files, difficult. So I need your help,

在我的main.cpp:

in my main.cpp:

#include "Sphere.h"

using namespace std;
.....
...
..

int main( void ) {
   Sphere *earth = new Sphere(sphere_start ,sphere_end);
...
..
.

在我的Sphere.h

in my Sphere.h

class Sphere
{

    public:
        Sphere(int,int);

}

和在我的Sphere.cpp

and in my Sphere.cpp

#include "Sphere.h"

using namespace std;

int sphere_start, sphere_end;   

Sphere::Sphere (int a, int b)
{
    sphere_start = a;
    sphere_end = b;
}

void Sphere::render(int i) 
{
   ....
   ..
   .

}

这是一个非常基本的代码,我认为会导致以下错误:

This is the very basic code that I think causes the following error:

main.cpp:14:20: fatal error: Sphere.h: No such file or directory
compilation terminated.

为什么?

推荐答案

Sphere.h必须与包含它的每个文件在同一目录中,否则编译器必须定向到搜索Sphere.h所在的目录。

Sphere.h must either be in the same directory as each file that includes it, or the compiler must be directed to search the directory in which Sphere.h is located.

这篇关于g ++找不到头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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