关于此问题的怪异之处是其他.cpp和.h文件可以找到该文件,但找不到该文件,它们都在SAME文件夹中。我的文件结构如下:
/Entity.h //被包含
/Graphics.cpp //可以包含
/Graphics.h //无法包含
/main.cpp //可以包含
/Physics.cpp //可以包含
/Physics.h //可以包含
Graphics.cpp,main.cpp,Physics.cpp,Physics.h都可以包含Entity.h,但Graphics.h不能。
这是Entity.h
#ifndef ENTITY_H
#define ENTITY_H
#include <vector>
#include <SFML/Graphics.hpp>
using namespace std;
struct entity
{
int ID;
vector<long double> position;
vector<long double> velocity;
vector<long double> acceleration;
sf::Color colour;
sf::CircleShape selfImage;
long double mass;
};
entity createEntity(long double x, long double y, long double xV, long double yV, long double m, int newID)
{
entity e;
// assign entity ID and increment entity ID count
e.ID = newID;
// initialise velocity, acceleration & position to 0
e.position.resize(2, 0);
e.velocity.resize(2, 0);
e.acceleration.resize(2, 0);
e.position = {x, y};
e.velocity = {xV, yV};
// setup self-image
e.colour = sf::Color (255, 0, 0);
e.selfImage.setFillColor(e.colour);
// initialise mass
e.mass = m;
return e;
};
#endif // ENTITY_H
这是Graphics.h
/*
* Graphics.h
*
* Created on: 26 Mar 2019
* Author: chris
*/
#ifndef GRAPHICS_H_
#define GRAPHICS_H_
#include <SFML/Graphics.hpp>
#include <vector>
#include <Entity.h>
class Graphics
{
public:
Graphics(int WIDTH, int HEIGHT);
~Graphics();
void update(vector<entity> entities);
int W_WIDTH;
int W_HEIGHT;
sf::RenderWindow window;
};
#endif /* GRAPHICS_H_ */
Physics.h,可以包含Entity.h的示例
#ifndef PHYSICS_H
#define PHYSICS_H
#include <Entity.h>
#include <vector>
using namespace std;
class Physics
{
long double G_CONST = 0.00000000006674;
public:
Physics();
virtual ~Physics();
const int MAP_WIDTH = 1000;
const int MAP_HEIGHT = 1000;
vector<vector<entity*>> gameMap;
vector<entity> entityList;
void addEntity(entity e);
int update();
protected:
private:
};
#endif // PHYSICS_H
控制台输出如下
make all
Building file: ../Graphics.cpp
Invoking: Cross G++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"Graphics.d" -MT"Graphics.o" -o "Graphics.o" "../Graphics.cpp"
In file included from ../Graphics.cpp:7:
../Graphics.h:12:10: fatal error: ./Entity.h: No such file or directory
#include <./Entity.h>
^~~~~~~~~~~~
compilation terminated.
make: *** [subdir.mk:26: Graphics.o] Error 1
"make all" terminated with exit code 2. Build might be incomplete.
我正在Debian上使用Eclipse。这让我感到困惑,我看不到文件的差异。
编辑: 在包含语句文件名周围使用“”代替<>可以解决此问题。然而,其他问题随之而来:(((((((