Home > Software engineering >  Are SDL's linker options mentioned in the official documentation?
Are SDL's linker options mentioned in the official documentation?

Time:07-29

I started using linker options lsd

I was not able to find out that I missed the linker options, without the help of this tutorial and other online forums. I was looking in the official documentation and wiki of the SDL and this is not mentioned anywhere.

Since this happens often to me (I go and try to use a library, the official documentation does not mention the important steps to compile the library. Sometimes it doesnt mention the files you need to include, others it does not mention the linker options one needs.). My question is:

How would someone using SDL library, find out they need to use these linker settings without the help of forums and tutorials? Could I found out from the errors it gave me upon compiling maybe?

I do not make the question general, I emphasize in this specific library, but the issue I have is general.

CodePudding user response:

On Linux, the standardized way of getting library flags is running pkg-config, which consults the .pc file distributed with the library. (Also CMake offers its own way of getting flags, if you're using it.)

You can (and should) use pkg-config on Windows too, if you use MinGW (without CMake). Installing it manually can be tedious, but MSYS2 provides it as a package. Libraries installed from MSYS2 normally work with pkg-config out of the box.

For self-downloaded SDL2 to work with it, the env variable PKG_CONFIG_PATH must be set to the directory with sdl2.pc (which you've downloaded).

Then running pkg-config --libs --define-prefix sdl2 will tell you the right flags. For me it prints -L/mingw64/lib -lSDL2main -lmingw32 -lSDL2main -lSDL2 -mwindows.

You can also consult the file sdl2.pc manually, with your own eyes. The flags are stored in it in plaintext.

  • Related