Wednesday 14 August 2019

linker - C++ Codeblocks & SFML library failure

They changed the way the SFML libraries are built a while ago, so you need to explicitly link them with the other libraries they depend on. This was to resolve problems with people using their own versions of these libraries, amongst other things.


The documentation here: http://www.sfml-dev.org/tutorials/2.3/start-cb.php does provide the information you need, though maybe not as obviously as it could.


I think for this particular error, if you also link with -lwinmm and maybe -lgdi32 it'll be able to find that symbol.


This is the full list of system libraries I link with:


openal32
vorbisfile
vorbisenc
vorbis
ogg
FLAC
jpeg
freetype
ws2_32
gdi32
opengl32
winmm

You don't need them all if you're not using all SFML features, e.g. the first bunch are only used by the audio library, ws2_32 is only needed for networking.


Note that the other you link them in matters - libraries must be listed before libraries they depend on. For my project setup, I set the above list of system libraries at the top level of the project build options. Then for the different targets (Debug, Release) I include the SFML libraries. e.g. for debug versions:


sfml-graphics-s-d
sfml-window-s-d
sfml-network-s-d
sfml-system-s-d
sfml-main-d

For the release versions, same names but without the -d suffix.


Then, make sure on the linker settings tab the "Policy" is set to Prepend target options to project options so they get inserted on the command line before the libraries you configured for the top-level project.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...