相关疑难解决方法(0)

将SDL2与CMake一起使用

我正在尝试使用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.

c++ cmake sdl-2

18
推荐指数
5
解决办法
3万
查看次数

LNK2019 - 未解析的外部符号 - C++ - SDL2 库

我正在尝试初始化我的游戏窗口,但无法克服此错误。我试过了:

  • 双重和三重检查我所有的代码是否有语法错误
  • 检查 SDL2 库是否正确包含在我的项目中

请参阅以下代码供您参考:

头文件:

#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)

c++ sdl sdl-2

2
推荐指数
1
解决办法
6195
查看次数

标签 统计

c++ ×2

sdl-2 ×2

cmake ×1

sdl ×1