SFML community forums

Help => General => Topic started by: Martocticvs on December 04, 2011, 03:30:14 pm

Title: SFML 2.0 linking issue
Post by: Martocticvs on December 04, 2011, 03:30:14 pm
I'm relatively new to C++ etc, so I'm sure I'm doing something wrong or missing something, but I'm having trouble getting SFML 2.0 to work.

I'm using Code::Blocks 10.05 as my IDE, and my compiler is MinGW (the TDM-GCC distribution, version 4.6.1).

I have followed the installation tutorial, and have compiled both the Debug and Release versions (static) without errors. (There were some errors initially, as the TDM install does not include the files libgdi32.a, libopengl32.a, libwinmm.a or libws2_32.a - they were present in the SFML 1.6 zip though so I copied them over from there, and then everything worked fine.)

In CMake, I have set BUILD_SHARED_LIBS to FALSE, STATIC_STD_LIBS to TRUE, and have altered the two compiler exes to x86_64-w64-mingw32-g++.exe and x86_64-w64-mingw32-gcc.exe, to match what I use in code::blocks, as per the TDM instructions. I have done it with the default g++.exe and gcc.exe with identical results.

In Code::Blocks I started a new project, copied in the code from the 1.6 tutorial:
Code: [Select]
#include <SFML/System.hpp>
#include <iostream>

int main()
{
    sf::Clock Clock;
    while (Clock.GetElapsedTime() < 5.f)
    {
        std::cout << Clock.GetElapsedTime() << std::endl;
        sf::Sleep(0.5f);
    }

    return 0;
}


and I have set up search directories (compiler points to \include, linker points to \lib) in the global settings, and in the project build options I have set link options -lsfml-system-s-d for debug and -lsfml-system-s for release. I have no #defines set.

When I build for debug I get the following errors:
Code: [Select]
D:/Development/Projects/SFML Test/main.cpp:6: undefined reference to `__imp__ZN2sf5ClockC1Ev'
D:/Development/Projects/SFML Test/main.cpp:9: undefined reference to `__imp__ZNK2sf5Clock14GetElapsedTimeEv'
D:/Development/Projects/SFML Test/main.cpp:10: undefined reference to `__imp__ZN2sf5SleepEj'
D:/Development/Projects/SFML Test/main.cpp:7: undefined reference to `__imp__ZNK2sf5Clock14GetElapsedTimeEv'


and for release:
Code: [Select]
obj\Release\main.o:main.cpp:(.text.startup+0x19): undefined reference to `__imp__ZN2sf5ClockC1Ev'
obj\Release\main.o:main.cpp:(.text.startup+0x20): undefined reference to `__imp__ZNK2sf5Clock14GetElapsedTimeEv'
obj\Release\main.o:main.cpp:(.text.startup+0x2f): undefined reference to `__imp__ZN2sf5SleepEj'


I am stumped!
Title: SFML 2.0 linking issue
Post by: Nexus on December 04, 2011, 03:43:11 pm
Why do you enable STATIC_STD_LIBS? You usually link the runtime and standard library (not SFML) dynamically.

And if you link SFML statically (BUILD_SHARED_LIBS disabled), you have to define the macro SFML_STATIC in your project.
Title: SFML 2.0 linking issue
Post by: Martocticvs on December 04, 2011, 04:12:38 pm
I'd misunderstood what that was for - I have recompiled with that set to FALSE now.

Adding that define solved it - the project builds perfectly now - thanks :D

SFML_STATIC isn't mentioned in the tutorial, incidentally... which would be why I didn't put it in.
Title: SFML 2.0 linking issue
Post by: Laurent on December 04, 2011, 06:18:03 pm
Quote
SFML_STATIC isn't mentioned in the tutorial, incidentally... which would be why I didn't put it in

Well, this is probably because there is no tutorial (this detail doesn't belong to "compiling SFML", but rather to "getting started with SFML") :D
Title: SFML 2.0 linking issue
Post by: Martocticvs on December 04, 2011, 06:37:37 pm
I meant in the 1.6 getting started tutorial, sorry :) Same place I lifted the sample code.
Title: SFML 2.0 linking issue
Post by: Laurent on December 04, 2011, 07:53:41 pm
In SFML 1.6 it's SFML_DYNAMIC, which is explained in the tutorials.