#complete beginner sdl including

1 messages · Page 1 of 1 (latest)

thick halo
#

so i already spent my whole day trying to get sdl to work with my c++, heres what i have now
makefile:

    g++ -I src\include -L C:\Users\48608\Desktop\cpp\sdlproject\src\x64lib -o main main.cpp -lSDL2main -lSDL2```
c++ tutorial code 💀:
```#include <iostream>
#include <SDL2/SDL.h>

const int WIDTH = 800, HEIGHT = 800;

int main( int argc, char *argv[] ) {
    SDL_Init( SDL_INIT_EVERYTHING);

    SDL_Window *window = SDL_CreateWindow("sdl lol", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH, HEIGHT, SDL_WINDOW_ALLOW_HIGHDPI);

    if (NULL == window) {
        std::cout << "Couldnt create window: " << SDL_GetError() << std::endl;
        return 1;
    }

    SDL_Event windowEvent;

    while (true) {
        if (SDL_PollEvent(&windowEvent)) {
            if (SDL_QUIT == windowEvent.type) {
                break;
            }
        }
    }

    SDL_DestroyWindow( window );
    SDL_Quit();

    return EXIT_SUCCESS;
}```

directories (check image)
earnest capeBOT
#

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 run !howto ask.

thick halo
#

yeah so it gives an error, i was trying and trying with chatgpt until it recognizes the directories, but now it says that it doesnt recognize the functions used

g++ -I src\include -L C:\Users\48608\Desktop\cpp\sdlproject\src\x64lib -o main main.cpp -lSDL2main -lSDL2
C:\Users\48608\AppData\Local\Temp\ccWRK8ae.o:main.cpp:(.text+0xf): undefined reference to `SDL_Init'
C:\Users\48608\AppData\Local\Temp\ccWRK8ae.o:main.cpp:(.text+0x43): undefined reference to `SDL_CreateWindow'
C:\Users\48608\AppData\Local\Temp\ccWRK8ae.o:main.cpp:(.text+0x51): undefined reference to `SDL_GetError'
C:\Users\48608\AppData\Local\Temp\ccWRK8ae.o:main.cpp:(.text+0x96): undefined reference to `SDL_PollEvent'
C:\Users\48608\AppData\Local\Temp\ccWRK8ae.o:main.cpp:(.text+0xb7): undefined reference to `SDL_DestroyWindow'
C:\Users\48608\AppData\Local\Temp\ccWRK8ae.o:main.cpp:(.text+0xbc): undefined reference to `SDL_Quit'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:2: all] Error 1```

chatgpt couldnt help me further...
thick halo
thorny thicket
thick halo
thorny thicket
# thick halo mingw

right, to learn how to add external libraries to your porgram like SDL you need to read the documentation of the command g++ and learn what the comand line arguments you passed are actually doing

thorny thicket
thick halo
thorny thicket
thick halo
thorny thicket
#

here you need to learn how include works

#

when you use #include "header.h"

#

the compiler will try to look for the current directory first, and then it will look in the include directories that were specified

#

to specify an include directory you use -I<insert full path_here>

#

this parameter is described in g++ docs

#

do not use relative apths in the filesystem, use full paths there

thick halo
thick halo
#

yes?

thorny thicket
#

they get recognised

#

so compilation phase passes, but

#

the linking phase

#

where you need to specify where exactly is the implementation of SDL2's functions and so on

#

is not passing because the linker can't find the implementation of the functions from the error message

#

meaning, you have a missing linker parameter

thorny thicket
#

you are missing some of SDL2's libraries

thick halo
# thorny thicket send me a link to the tutorial you are following

well i completely modified the makefile command but everything else like in the tutorial https://www.youtube.com/watch?v=jUZZC9UXyFs

⭐ Kite is a free AI-powered coding assistant that will help you code faster and smarter. The Kite plugin integrates with all the top editors and IDEs to give you smart completions and documentation while you’re typing. I've been using Kite for 6 months and I love it! https://www.kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campa...

▶ Play video
thorny thicket
#

you don't have them

thick halo
#

...

#

okay lemme download them

thick halo
#

so i had to download the same sdl as the guy in the video...

thorny thicket
thick halo
thorny thicket
thorny thicket
thick halo
#

i still dont understand

#

also i just realized that the .exe doesnt run.....

thorny thicket
thick halo
#

it means "the application wasnt opened correctly" (?)

thorny thicket
thick halo
thick halo
#

idk what to do now 💀

#

!solved