codelite sdl2 没有编译

codelite sdl2 not compiling

我安装了 arch linux 作为我的操作系统。 我安装了 codelite 作为我的 c++ IDE。 我下载了SDL2。

我试图让 SDL 与 c++ 一起工作,但我所做的一切都不起作用。

我已经搜索了几个小时试图让它工作,但它就是不想工作。我找不到库链接器的任何 .dll 或 .a 或 .so 文件。当我在 windows 时,我必须找到它们并将目录放入链接器设置中,但我找不到任何 .dll。现在它可以识别 SDL_Window 和 SDL_Surface。但是我在尝试构建我的项目时遇到错误,说 undefined reference to...

这是我的源代码:

#include <SDL2/SDL.h>
#include <stdio.h>

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

bool init();
bool loadMedia();
void close();

SDL_Window* window = NULL;
SDL_Surface* gScreenSurface = NULL;
SDL_Surface* gHelloWorld = NULL;

bool init() {
    bool success = true;
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        printf("SDL could not initialize! SDL Error: %s\n", SDL_GetError());
        success = false;
    } else {
        window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
        if (window == NULL) {
            printf("Window could not be created! SDL Error: %s\n", SDL_GetError());
            success = false;
        } else {
            gScreenSurface = SDL_GetWindowSurface(window);
        }
    }

    return success;
}

bool loadMedia() {
    bool success = true;
    gHelloWorld = SDL_LoadBMP("hello_world.bmp");
    if (gHelloWorld == NULL) {
        printf("Unable to load image %s! SDL Error: %s\n", "hello_world.bmp", SDL_GetError());
        success = false;
    }

    return success;
}

void close() {
    SDL_FreeSurface(gHelloWorld);
    gHelloWorld = NULL;

    SDL_DestroyWindow(window);
    window = NULL;

    SDL_Quit();
}

int main(int argc, char **argv)
{
    if (!init()) {
        printf("Failed to initialize!\n");
    } else {
        if (!loadMedia()) {
            printf("Failed to load media!\n");
        } else {
            SDL_BlitSurface(gHelloWorld, NULL, gScreenSurface, NULL);
            SDL_UpdateWindowSurface(window);
            SDL_Delay(3000);
        }
    }

    close();

    return 0;
}

这是我的输出:

/bin/sh -c '/usr/bin/make -j4 -e -f  Makefile'
----------Building project:[ Test - Debug ]----------
make[1]: Entering directory '/home/vinny/Documents/Projects/Test'
/usr/bin/g++  -c  "/home/vinny/Documents/Projects/Test/main.cpp" -g -O0 -Wall  -o ./Debug/main.cpp.o -I. -I. -I/home/vinny/Downloads/SDL2-2.0.7/include
/usr/bin/g++ -o ./Debug/Test @"Test.txt" -L.
./Debug/main.cpp.o: In function `init()':
/home/vinny/Documents/Projects/Test/main.cpp:17: undefined reference to `SDL_Init'
/home/vinny/Documents/Projects/Test/main.cpp:18: undefined reference to `SDL_GetError'
/home/vinny/Documents/Projects/Test/main.cpp:21: undefined reference to `SDL_CreateWindow'
/home/vinny/Documents/Projects/Test/main.cpp:23: undefined reference to `SDL_GetError'
/home/vinny/Documents/Projects/Test/main.cpp:26: undefined reference to `SDL_GetWindowSurface'
./Debug/main.cpp.o: In function `loadMedia()':
/home/vinny/Documents/Projects/Test/main.cpp:35: undefined reference to `SDL_RWFromFile'
/home/vinny/Documents/Projects/Test/main.cpp:35: undefined reference to `SDL_LoadBMP_RW'
/home/vinny/Documents/Projects/Test/main.cpp:37: undefined reference to `SDL_GetError'
./Debug/main.cpp.o: In function `close()':
/home/vinny/Documents/Projects/Test/main.cpp:45: undefined reference to `SDL_FreeSurface'
/home/vinny/Documents/Projects/Test/main.cpp:48: undefined reference to `SDL_DestroyWindow'
/home/vinny/Documents/Projects/Test/main.cpp:51: undefined reference to `SDL_Quit'
./Debug/main.cpp.o: In function `main':
/home/vinny/Documents/Projects/Test/main.cpp:62: undefined reference to `SDL_UpperBlit'
/home/vinny/Documents/Projects/Test/main.cpp:63: undefined reference to `SDL_UpdateWindowSurface'
/home/vinny/Documents/Projects/Test/main.cpp:64: undefined reference to `SDL_Delay'
collect2: error: ld returned 1 exit status
make[1]: *** [Test.mk:79: Debug/Test] Error 1
make[1]: Leaving directory '/home/vinny/Documents/Projects/Test'
make: *** [Makefile:5: All] Error 2
====14 errors, 0 warnings====

我是 linux OS 的新手,所以我可能没有尝试过所有方法。请帮忙。自从我切换到 linux 后,我就没法编程了。 :(

@Aram 在他的评论中所说的 - 除了它需要是 -lSDL2 而不是 -lSDL,因为它是您包含和编程的 SDL2,而不仅仅是 SDL。