本文介绍了CLion,SDL2,CMake:无可用的视频设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to start using SDL2 (with CLion as my IDE), but I'm running into errors. I'm on Pop!_OS 19.10 (based on ubuntu)

以下是相关的项目文件:

Here are the relevant project files:

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.错误结果相同.另外,我跑了

I have tried setting DISPLAY=:0.0 in CLion's run configurations. Same error results. Futhermore, I ran

echo $DISPLAY
:1

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

and tried using :1 as well, same error persists.

推荐答案

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

Removing /usr/local/bin/sdl2-config,/usr/local/include/SDL2 and /usr/local/lib/libSDL2* (as suggested by Botje) solved the problem due to the self-built version of SDL2 missing the required video headers.

这篇关于CLion,SDL2,CMake:无可用的视频设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 09:26