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

Author Topic: Linker Error Statically linking manually built SFML in MinGW 4.8.2 on Windows  (Read 4010 times)

0 Members and 1 Guest are viewing this topic.

ozma77

  • Newbie
  • *
  • Posts: 3
    • View Profile
Hello everyboy. I'm new to game development, altough not in programming and I'm taking a college course on game development in which I can use SFML or SDL. I decided to go with SFML, but I have ran into some errors.
First of all, I tried to use pre-built SFML 2.1 for Codeblocks, but I got lots of linker errors, and, after doing some research I realized it was due to the fact I'm using MinGW 4.8.2 instead of 4.7.2. So, I manually built SFML 2.1 using Cmake as explained in the tutorial on the SFML site ( further reference here: http://www.sfml-dev.org/tutorials/2.1/compile-with-cmake.php). The compilation and installation was a complete sucess. The trouble I have is, after setting Code::Blocks as is detailed here: http://www.sfml-dev.org/tutorials/2.1/start-cb.php I still got lots of linker errors. I did research on the web and I found a post : http://en.sfml-dev.org/forums/index.php?topic=13881.0
The post above, to summarize, says that you need to set the compiler like this:
Defines
GLEW_STATIC
SFML_STATIC
UNICODE

Libraries
sfml-audio-s
sfml-graphics-s
sfml-network-s
sfml-window-s
sfml-system-s
sndfile
openal32
jpeg
glew
freetype
ws2_32
gdi32
opengl32
winmm

I have tried, but I got the very same errors everytime, and to be honest I don't know what else to do.
That's why I decided to post my Build Log here, to see if you guys can help me.

Disclaimer: By the way, it's a MUST, for the course to link SFML statically, that's the reason I'm struggling to make the most basic example run -or at least compile-.
I really really appreciate any kind of help!

BUILD LOG:
g++.exe -Os -O3 -Wmain -pedantic-errors -Wfatal-errors -Wextra -Wall -DGLEW_STATIC -DSFML_STATIC -DUNICODE -IC:\MinGW\include -IC:\SFML-2.1-MinGW\include -c "C:\Users\Alonso\Desktop\C++ Games\Tic Tac Toe\test.cpp" -o "C:\Users\Alonso\Desktop\C++ Games\Tic Tac Toe\test.o"
g++.exe -LC:\MinGW\include -LC:\MinGW\lib -LC:\SFML-2.1-MinGW\lib -o "C:\Users\Alonso\Desktop\C++ Games\Tic Tac Toe\test.exe" "C:\Users\Alonso\Desktop\C++ Games\Tic Tac Toe\test.o"   C:\SFML-2.1-MinGW\lib\libsfml-audio-s.a C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a C:\SFML-2.1-MinGW\lib\libsfml-network-s.a C:\SFML-2.1-MinGW\lib\libsfml-window-s.a C:\SFML-2.1-MinGW\lib\libsfml-system-s.a C:\SFML-2.1-MinGW\lib\libsndfile.a C:\SFML-2.1-MinGW\lib\libopenal32.a C:\SFML-2.1-MinGW\lib\libjpeg.a C:\SFML-2.1-MinGW\lib\libglew32.a C:\SFML-2.1-MinGW\lib\libfreetype.a
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderWindow.cpp.obj):RenderWindow.cpp:(.text+0x355): undefined reference to `glReadPixels'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0xf8): undefined reference to `glClearColor'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x6f6): undefined reference to `glMatrixMode'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x6fb): undefined reference to `glPopMatrix'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x705): undefined reference to `glMatrixMode'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x70a): undefined reference to `glPopMatrix'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x714): undefined reference to `glMatrixMode'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x719): undefined reference to `glPopMatrix'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x71e): undefined reference to `glPopClientAttrib'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x75b): undefined reference to `glDisable'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x765): undefined reference to `glDisable'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x76f): undefined reference to `glDisable'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x779): undefined reference to `glDisable'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x783): undefined reference to `glEnable'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x78d): undefined reference to `glEnable'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x797): undefined reference to `glMatrixMode'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x7a1): undefined reference to `glEnableClientState'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x7ab): undefined reference to `glEnableClientState'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x7b5): undefined reference to `glEnableClientState'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x7c4): undefined reference to `glPolygonMode'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x7e3): undefined reference to `glBlendFunc'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x801): undefined reference to `glLoadMatrixf'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x88d): undefined reference to `glPushClientAttrib'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x897): undefined reference to `glPushAttrib'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x8a1): undefined reference to `glMatrixMode'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x8a6): undefined reference to `glPushMatrix'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x8b0): undefined reference to `glMatrixMode'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x8b5): undefined reference to `glPushMatrix'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x8bf): undefined reference to `glMatrixMode'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x8c4): undefined reference to `glPushMatrix'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0xa1a): undefined reference to `glViewport'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0xa24): undefined reference to `glMatrixMode'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0xa3c): undefined reference to `glLoadMatrixf'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0xa46): undefined reference to `glMatrixMode'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0xb08): undefined reference to `glBlendFunc'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0xb28): undefined reference to `glBlendFunc'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0xb4b): undefined reference to `glBlendFunc'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0xb6b): undefined reference to `glBlendFunc'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0xcf5): undefined reference to `glVertexPointer'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0xd0e): undefined reference to `glColorPointer'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0xd27): undefined reference to `glTexCoordPointer'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0xd3c): undefined reference to `glDrawArrays'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0xd95): undefined reference to `glLoadMatrixf'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0xdc0): undefined reference to `glLoadMatrixf'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x107): undefined reference to `glClear'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0x728): undefined reference to `glPopAttrib'
C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj):RenderTarget.cpp:(.text+0xe04): undefined reference to `glLoadMatrixf'
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.8.2/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\SFML-2.1-MinGW\lib\libsfml-graphics-s.a(RenderTarget.cpp.obj): bad reloc address 0x0 in section `.pdata'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 1 second(s))
47 error(s), 0 warning(s) (0 minute(s), 1 second(s))
 

NOTES: I use Code:Blocks 13.12, with the MinGW 4.8.2 got from the Nuwen Site (http://nuwen.net/mingw.html) on Windows 7 Home Premium 64 bit. 

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Triple check your Code::Blocks linker/project settings. It isn't linking some of the libraries you listed. If it still doesn't resolve the problem, post screenshots of your linker settings page where you entered all these libraries.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

ozma77

  • Newbie
  • *
  • Posts: 3
    • View Profile
Hello, thanks for the help! I realized you are right. I'm pasting my settings. By the way, I forgot to say I built MinGW makefiles directly instead of Codeblocks project. That's why I'm changing compiler global settings this way:

http://prntscr.com/2zwl4u
http://prntscr.com/2zwlaq
http://prntscr.com/2zwlge
http://prntscr.com/2zwlj3

I checked the generated files and I couldn't find the missing libraries (openGL32, ws2_32, etc). Shall I get them from other place? Also, checking the thread on my previous post I think I read that sfml-graphics-s calls internally both glew and opengl. If that's the case, I'm really needed to link against those libraries?
Please, I really appreciate your help!

PS: As I side note, if I try to link dinamically against SFML using the dll's I can run the example. I don't know if that info works ^^

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Random comment:

Don't specify both -Os and -O3 - use one or the other, they don't mix.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
You need to link against opengl32 and ws2_32. You don't need to specify the full path, but it's enough to add the library name, as long as it's either in the compiler's lib path or in the path specified for the linker.

For example (I don't use networking):

Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

ozma77

  • Newbie
  • *
  • Posts: 3
    • View Profile
Dude, thanks! I tried to do as you said and finally got SFML working with this config:

http://prntscr.com/2zwwiv

Thanks a lot!! :D