#SDL2 shows header files but not actual library files

6 messages · Page 1 of 1 (latest)

delicate granite
#

Hello all.

I am trying to get SDL2 working on my (arch) linux computer, but unfortunately, it is not working.
I am trying to get it to work with CMake. (currently using CLion)

Here is my CMakeLists

project(untitled)

set(CMAKE_CXX_STANDARD 17)
add_executable(untitled main.cpp)

include_directories(/usr/local/include/)
target_link_libraries(untitled /usr/local/lib/)```

Here is my C++ code (its a basic starter code)
```#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 would be that it compiles fine, and runs as normal. Unfortunately, the actual result is as shows:
wispy badgeBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

delicate granite
#

/usr/bin/ld: /tmp/ccER8Ol6.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

#

I have tried using the package from the AUR, and using the package directly from their website.

flint star
#

you're not telling cmake that it needs to use SDL2

delicate granite
#

Oh, thats unfortunate. how would i go about doing that?