CLion、SDL2、CMake:没有可用的视频设备

CLion, SDL2, CMake: No available video device

我正在尝试开始使用 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,同样的错误仍然存​​在。

删除 /usr/local/bin/sdl2-config/usr/local/include/SDL2/usr/local/lib/libSDL2*(按照 Botje 的建议)解决了由于 self-built 版本的 SDL2 缺少所需视频 headers.