codelite sdl2没有编译

时间:2018-02-09 12:04:08

标签: sdl archlinux undefined-reference codelite

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

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

我已经搜索了几个小时试图让它工作,它只是不想工作。我无法找到库链接器的任何.dll或.a或.so文件。当我在Windows上时,我不得不找到它们并将目录放在链接器设置中,但是我找不到任何.dll' s。现在它识别SDL_Window和SDL_Surface。但是我在尝试构建我的项目时遇到错误的引用...

这是我的源代码:

#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操作系统的新手,所以我可能没有尝试过所有的东西。请帮忙。自从我切换到linux后,我还没有能够编程。 :(

1 个答案:

答案 0 :(得分:1)

@Aram在评论中说了什么 - 除了它需要-lSDL2而不是-lSDL,因为它是SDL2,你包括和编程,而不仅仅是SDL。