KingKoopa
KingKoopa

Reputation: 99

gcc/g++ using linkerflag "-lSDL2"

acordingly to lazyfoos sdl tutorial https://lazyfoo.net/tutorials/SDL/01_hello_SDL/linux/cli/index.php i setup sdl2. (and it runs with the given Terminal command) "g++ 01_hello_SDL.cpp -w -lSDL2 -o 01_hello_SDL"

i cant remember the-lsdl2 flag and i don't know why i have to use it. i also cant comprehend why gcc already know a SDL realatet option like -lsdl2.

how do people know they have to use this flag? i cant find anything usefull on this, people seem to just take it as a fact and tutorials didn't tell why to do so.

hope someone have time for this, i would be glad if i could gain knowledge to set up other libaries by my self next time

Upvotes: 0

Views: 482

Answers (1)

3CxEZiVlQ
3CxEZiVlQ

Reputation: 38508

Professionals do not need to remember compiler and linker flags. They use cross-platform pkgconfig

pkg-config --cflags --libs sdl2

For example it can be used in a shell

g++ 01_hello_SDL.cpp -w -o 01_hello_SDL `pkg-config --cflags --libs sdl2`

Upvotes: 1

Related Questions