我正在尝试使用CLion来创建一个SDL2项目.问题是使用#include时无法找到SDL标头.
我的CMakeLists.txt文件:
cmake_minimum_required(VERSION 2.8.4)
project(ChickenShooter)
set(SDL2_INCLUDE_DIR C:/SDL/SDL2-2.0.3/include)
set(SDL2_LIBRARY C:/SDL/SDL2-2.0.3/lib/x64)
include_directories(${SDL2_INCLUDE_DIR})
set(SOURCE_FILES main.cpp)
add_executable(ChickenShooter ${SOURCE_FILES})
target_link_libraries(ChickenShooter ${SDL2_LIBRARY})
Run Code Online (Sandbox Code Playgroud)
我的测试main.cpp:
#include <iostream>
#include "SDL.h" /* This one can't be found */
int main(){
if (SDL_Init(SDL_INIT_VIDEO) != 0){
std::cout << "SDL_Init Error: " << SDL_GetError() << std::endl;
return 1;
}
SDL_Quit();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
谢谢你能给我的任何帮助.
编辑:我正在使用Windows,而CLion配置为使用cygwin64.
我正在尝试初始化我的游戏窗口,但无法克服此错误。我试过了:
请参阅以下代码供您参考:
头文件:
#ifndef Game_hpp
#define Game_hpp
#include "SDL.h"
#include <iostream>
class Game
{
public:
Game();
~Game();
void init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen);
void handleEvents();
void update();
void render();
void clean();
bool running()
{
return isRunning;
}
private:
bool isRunning;
SDL_Window *window;
SDL_Renderer *renderer;
};
#endif /* Game_hpp */
Run Code Online (Sandbox Code Playgroud)
Game.cpp - 定义函数的地方
#include "Game.h"
Game::Game()
{}
Game::~Game()
{}
void Game::init(const char *title, int xpos, int ypos, int width, …Run Code Online (Sandbox Code Playgroud)