我正在尝试使用SDL,VS Code和g ++编译器制作游戏,但是我发现这很烦人。
我在g ++编译器上使用-mwindows选项来隐藏与SDL窗口一起提供的控制台窗口,但该错误仅在我使用它时出现(注释时,它编译时没有错误,但具有令人讨厌的控制台窗口在后面)。
错误:
g++ -g -Wall -mwindows -IG:/SDL2-2.0.8/x86_64-w64-mingw32/include/SDL2/ Draw/draw.cpp Game/game_object.cpp Game/game.cpp main.cpp -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -LG:/SDL2-2.0.8/x86_64-w64-mingw32/lib -std=c++11 <
Game/game_object.cpp:10:47: error: no 'void Planet::DrawPlanet(SDL_Renderer*)' member function declared in class 'Planet'
void Planet::DrawPlanet(SDL_Renderer *renderer)
^
The terminal process terminated with exit code: 1
VSC的task.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build Game Sargittarium 2.0",
"type": "shell",
"command": "g++",
"args": [
//Config parameters
"-g",
"-Wall",
"-mwindows",//This is what is giving me the error
//Include directories
"-IG:/SDL2-2.0.8/x86_64-w64-mingw32/include/SDL2/",
//Sets the files in the program
"Draw/draw.cpp",
"Game/game_object.cpp",
"Game/game.cpp",
"main.cpp",//Main needs to be the last one
//Libraries files and directories
"-lmingw32",
"-lSDL2main",
"-lSDL2",
"-lSDL2_image",
"-LG:/SDL2-2.0.8/x86_64-w64-mingw32/lib",
"-std=c++11"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
game_object.h:
#include <SDL.h>
#include "../Draw/draw.h"
class Planet
{
private:
int pos_x;
int pos_y;
int radius;
public:
Planet(int x, int y, int r);
void DrawPlanet(SDL_Renderer *renderer);
};
game_object.cpp:
#include "game_object.h"
Planet::Planet(int pos_x, int pos_y, int radius)
{
this->pos_x = pos_x;
this->pos_y = pos_y;
this->radius = radius;
}
void Planet::DrawPlanet(SDL_Renderer *renderer)
{
Draw::CircleFill(renderer, pos_x, pos_y, radius, 255, 255, 255, 255);
}
编辑:
更改文件名即可解决问题,谢谢!