Codelite SDL2 не компилируется
Я установил Arch Linux в качестве операционной системы. У меня установлена codelite в качестве моей C++ IDE. Я загрузил SDL2.
Я пытаюсь заставить SDL работать с C++, но все, что я делаю, не работает.
Я искал часы, пытаясь заставить это работать, а оно просто не хочет работать. Я не могу найти файлы.dll или.a или.so для компоновщика библиотеки. Когда я был на окнах, я должен был найти их и поместить каталоги в настройках компоновщика, но я не могу найти.dll. Теперь он распознает 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 ответ
Что @Aram сказал в своем комментарии - кроме того, что должно быть -lSDL2
вместо -lSDL
, поскольку это SDL2, который вы включаете и программируете, а не просто SDL.