CLion,SDL2,CMake:无可用的视频设备

问题描述 投票:1回答:1

我正在尝试开始使用SDL2(以CLion作为我的IDE),但是我遇到了错误。我正在使用Pop!_OS 19.10(基于ubuntu)

以下是相关的项目文件:

CMakeLists.txt

cmake_minimum_required(VERSION 3.13)
project(sdlpractice)

set(CMAKE_CXX_STANDARD 20)

find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})

add_executable(sdlpractice main.cpp)
target_link_libraries(sdlpractice ${SDL2_LIBRARIES})

Main.cpp

#include "SDL2/SDL.h"
#include "stdio.h"

const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;

int main(int argc, char* args[]) {
    // The window we will be rendering to
    SDL_Window * ptrWindow = NULL;
    // The surface contained by the window
    SDL_Surface * ptrScreenSurface = NULL;
    // Initialize SDL
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
    } else {
        // Create window
        ptrWindow = SDL_CreateWindow("SDL Practice",
                SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
                SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
        if (ptrWindow == nullptr) {
            printf("Window creation failed: %s\n", SDL_GetError());
        }
        // Get window surface
        ptrScreenSurface = SDL_GetWindowSurface(ptrWindow);
        // Fill the surface white
        SDL_FillRect(ptrScreenSurface, NULL, SDL_MapRGB(ptrScreenSurface->format, 0xFF, 0xFF, 0xFF));
        // Update the surface
        SDL_UpdateWindowSurface(ptrWindow);
        // Wait 2 seconds
        SDL_Delay(2000);
        // Destroy window, quit SDL subsystems
        SDL_DestroyWindow(ptrWindow);
        SDL_Quit();
        return 0;
    }
}

我收到以下错误:

SDL could not initialize! SDL_Error: No available video device

我已经尝试在CLion的运行配置中设置DISPLAY =:0.0。错误结果相同。另外,我跑了

echo $DISPLAY 
:1

并且也尝试使用:1,同样的错误仍然存​​在。

c++ cmake sdl sdl-2 clion
1个回答
0
投票

删除/usr/local/bin/sdl2-config/usr/local/include/SDL2/usr/local/lib/libSDL2*(由Botje建议)解决了此问题,因为SDL2的自建版本缺少必需的视频标题。

© www.soinside.com 2019 - 2024. All rights reserved.