arsogio996
arsogio996

Reputation: 41

C++ Codeblocks & SFML library failure

I'm been trying to get started with the SFML library. However all my attempts so far have resulted in numerous errors. The code below is about as simple a program as I've come up with, but is still give me three error (Build Log Listed Below)

#include <SFML/System.hpp>

int main()
{
    sf::sleep(sf::seconds(1.f));
    return 0;
}

-------------- Build: Release in SFML_TEST_14-3 (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -LC:\SFML-2.3.2\lib -LC:\SFML-2.3.2\lib -LC:\SFML-2.3.2\lib -o bin\Release\SFML_TEST_1.exe obj\Release\main.o  -s  -lsfml-system-s -lsfml-system-s -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lsfml-graphics-s-d -lsfml-window-s-d -lsfml-system-s-d
C:\SFML-2.3.2\lib/libsfml-system-s.a(SleepImpl.cpp.obj):SleepImpl.cpp:(.text+0x21): undefined reference to `timeGetDevCaps@8'
C:\SFML-2.3.2\lib/libsfml-system-s.a(SleepImpl.cpp.obj):SleepImpl.cpp:(.text+0x2f): undefined reference to `timeBeginPeriod@4'
C:\SFML-2.3.2\lib/libsfml-system-s.a(SleepImpl.cpp.obj):SleepImpl.cpp:(.text+0x50): undefined reference to `timeEndPeriod@4'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
3 error(s), 0 warning(s) (0 minute(s), 0 second(s))

I'm working (or rather not working) with Code::Blocks 13.12, MinGW 5.1.3, and SFML 2.3.2 for gcc 4.8.1. I've tried using older versions of these but nothing.

I'm fairly certain these errors are associated with the library linking but I don't know where the error is emanating from. I've linked everything according to SFML-dev's tutorial; with a without altering the global compiler settings.

Project Build Information

I've rebuilt & reinstalled everything several times. Used static and dynamic forms of the SFML .a files and tried using TDM GCC. I've used a sample program with the least complexity I could manage. Can anyone tell me what I'm doing wrong. Is the linker not finding some file or was the code I used invalid in some way? Could I be missing some .dll that I'm not aware of?

Window 8.1

MinGW Directory C:\MinGW

SFML Directory C:\SFML2-3-2

Upvotes: 0

Views: 1317

Answers (1)

notmyfriend
notmyfriend

Reputation: 245

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.

Upvotes: 1

Related Questions