trying to get SDL2 working in CLion on (arch) Linux
已回答
Hello.
Here is my CMakeLists
cmake_minimum_required(VERSION 3.0)
project(untitled)
set(CMAKE_CXX_STANDARD 17)
add_executable(untitled main.cpp)
include_directories(/usr/local/include/SDL2/)
target_link_libraries(untitled /usr/local/lib/libSDL2-2.0.so.0)
Here is my SDL2 code (its just a basic starter code i ripped from their website, so it should work)
#include <SDL2/SDL.h>
int main() {
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("SDL_Init Error: %s\n", SDL_GetError());
return 1;
}
SDL_Window* window = SDL_CreateWindow("Hello SDL", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, 0);
if (window == NULL) {
printf("SDL_CreateWindow Error: %s\n", SDL_GetError());
return 1;
}
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (renderer == NULL) {
printf("SDL_CreateRenderer Error: %s\n", SDL_GetError());
return 1;
}
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
SDL_Delay(2000); // Wait for 2 seconds
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
The expected result is that the program runs with no errors. Unfortunately, it spits out a bunch of errors.
Here are the errors.
/usr/bin/ld: /tmp/ccsZq7Xa.o: in function `main':
main.cpp:(.text+0xe): undefined reference to `SDL_Init'
/usr/bin/ld: main.cpp:(.text+0x1c): undefined reference to `SDL_GetError'
/usr/bin/ld: main.cpp:(.text+0x67): undefined reference to `SDL_CreateWindow'
/usr/bin/ld: main.cpp:(.text+0x77): undefined reference to `SDL_GetError'
/usr/bin/ld: main.cpp:(.text+0xae): undefined reference to `SDL_CreateRenderer'
/usr/bin/ld: main.cpp:(.text+0xbe): undefined reference to `SDL_GetError'
/usr/bin/ld: main.cpp:(.text+0xfd): undefined reference to `SDL_SetRenderDrawColor'
/usr/bin/ld: main.cpp:(.text+0x109): undefined reference to `SDL_RenderClear'
/usr/bin/ld: main.cpp:(.text+0x115): undefined reference to `SDL_RenderPresent'
/usr/bin/ld: main.cpp:(.text+0x11f): undefined reference to `SDL_Delay'
/usr/bin/ld: main.cpp:(.text+0x12b): undefined reference to `SDL_DestroyRenderer'
/usr/bin/ld: main.cpp:(.text+0x137): undefined reference to `SDL_DestroyWindow'
/usr/bin/ld: main.cpp:(.text+0x13c): undefined reference to `SDL_Quit'
collect2: error: ld returned 1 exit status
How would i fix this?
请先登录再写评论。
Hello!
Please take a look at https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000770164/comments/360000002010.