この問題を特定できないようですので、ここで質問しようと思いました。このエラーが通常表示される理由はわかっていますが、今回は理解できないようです。おそらく、私が知らない、または欠けている単純なものです。
g++ -c -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT src/Render.cpp -L/usr/lib/i386-linux-gnu -lSDL -lSDL_image
src/Render.cpp:8:1: error: ‘Render’ does not name a type
src/Render.cpp:13:1: error: ‘Render’ does not name a type
src/Render.cpp:18:14: error: ‘Render’ has not been declared
src/Render.cpp:31:6: error: ‘Render’ has not been declared
make: *** [Render.o] Error 1
これが私のcore.cpp、Makefile、およびRender.hです
Render.cpp
#ifndef _Render_h
#define _Render_h
#include <iostream>
#include "SDL/SDL_image.h"
using namespace std;
Render::Render()
{
}
Render::~Render()
{
}
SDL_Surface* Render::loadImg(string filename)
{
SDL_Surface* temp = NULL;
SDL_Surface* optimized = NULL;
if((temp = IMG_Load(filename.c_str())) != NULL)
{
optimized = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
}
return optimized;
}
void Render::applySurface(int x, int y, SDL_Surface* source,
SDL_Surface* destination)
{
SDL_Rect offset;
offset.x = x;
offset.y = y;
SDL_BlitSurface(source, NULL, destination, &offset);
}
#endif
コア.cpp
#include <iostream>
#include "SDL/SDL.h"
#include "Render.h"
using namespace std;
int main(int argc, char* args[])
{
string imgGoku = "src/imgs/Goku.bmp";
string imgVegeta = "src/imgs/Vegeta.png";
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;
SDL_Surface *message = NULL;
SDL_Surface *background = NULL;
SDL_Surface *screen = NULL;
Render rnd;
if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
return 1;
}
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT,
SCREEN_BPP, SDL_SWSURFACE);
if(screen == NULL)
{
return 1;
}
SDL_WM_SetCaption("Hello World", NULL);
rnd.applySurface(10,10,rnd.loadImg(imgGoku),screen);
if(SDL_Flip(screen) == -1)
{
return 1;
}
SDL_Delay(2000);
SDL_FreeSurface(message);
SDL_FreeSurface(background);
SDL_Quit();
return 0;
}
Render.h
#include "SDL/SDL.h"
using namespace std;
class Render{
public:
Render();
~Render();
SDL_Surface* loadImg(string filename);
void applySurface(int x, int y,
SDL_Surface* source,
SDL_Surface* destination);
};
メイクファイル
#Game Make file
TARGET = game.exe
OBJS = core.o \
Render.o \
SDL_CFLAGS := $(shell sdl-config --cflags)
SDL_LDFLAGS := $(shell sdl-config --libs) -lSDL_image
CFLAGS = -Wall
LIBS =
LDFLAGS =
$(TARGET): $(OBJS)
g++ $(CFLAGS) $(SDL_CFLAGS) -o $@ $(LDFLAGS) $(OBJS) $(SDL_LDFLAGS) $(LIBS)
%.o: src/%.cpp src/Render.h
g++ -c $(SDL_CFLAGS) $< $(SDL_LDFLAGS)
.PHONY: clean
clean:
rm -f $(TARGET) $(OBJS)