Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Static linking to SFML 2.0 libraries doesn't work  (Read 2478 times)

0 Members and 1 Guest are viewing this topic.

Pfeffer

  • Newbie
  • *
  • Posts: 4
    • View Profile
Static linking to SFML 2.0 libraries doesn't work
« on: June 01, 2013, 01:34:39 am »
I have a big project where I just moved from SFML 1.6 to 2.0. Dynamic linking worked fine until now. After changing to static linking I get this error:

src/input.o:input.cpp:(.text+0x1c): undefined reference to `_imp___ZN2sf6Window5closeEv'
src/input.o:input.cpp:(.text+0x1f3): undefined reference to `_imp___ZN2sf5Mouse11setPositionERKNS_7Vector2IiEERKNS_6WindowE'
src/input.o:input.cpp:(.text+0x21c): undefined reference to `_imp___ZN2sf8Keyboard12isKeyPressedENS0_3KeyE'
src/input_mode.o:input_mode.cpp:(.text+0x6c): undefined reference to `_imp___ZN2sf8Keyboard12isKeyPressedENS0_3KeyE'
src/application_context.o:application_context.cpp:(.text+0xaa): undefined reference to `_imp___ZN2sf9VideoMode18getFullscreenModesEv'
src/application_context.o:application_context.cpp:(.text+0xdd): undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'
src/application_context.o:application_context.cpp:(.text+0x11f): undefined reference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'
src/application_context.o:application_context.cpp:(.text+0x158): undefined reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'


Compiling is fine and I cleaned the project many times. I compiled the SFML 2.0 libraries by myself, with CMake and MinGW-GCC. The dynamic libraries worked fine. I have set BUILD_SHARED_LIBS = FALSE for compiling the static libs.

The result were this lib files (I only need this 3) which I added to the "lib" directory to my project:
  • libsfml-window-s.a
  • libsfml-system-s.a
  • libsfml-graphics-s.a

I used the following command to link with MinGW-GCC 4.7.2:
g++  -DSFML_STATIC -Iinc -std=gnu++0x -O3 -fmessage-length=0 -DNDEBUG  -o bin/SFML-Prototype-Release.exe (object files) -Llib -Lbin -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lFreeImage  -lglew32 -lglu32 -lopengl32

And having files in "bin" directory:
  • FreeImage.dll
  • glew32.dll
And files in "lib" directory:
  • libsfml-window-s.a
  • libsfml-system-s.a
  • libsfml-graphics-s.a
  • FreeImage.lib

Hard- & Software:
I am using Windows 7 Prof. 64bit on a 5 year old notebook hardware:
Intel 2 Duo P8600 - 2.4Ghz
Nvidia Geforce 9600M GT
4GB RAM
« Last Edit: June 01, 2013, 01:36:20 am by Pfeffer »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Static linking to SFML 2.0 libraries doesn't work
« Reply #1 on: June 01, 2013, 09:09:47 am »
-DSFML_STATIC is a compiler flag (it defines a new macro), not a linker flag.
Laurent Gomila - SFML developer

Pfeffer

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Static linking to SFML 2.0 libraries doesn't work
« Reply #2 on: June 01, 2013, 03:20:24 pm »
Since it was an link error, I totally thought the problem was with the link command, but I had to add the -DSFML_STATIC flag to the compile command.

Tank you.