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

Author Topic: SFML 2.2 Static linking  (Read 23716 times)

0 Members and 1 Guest are viewing this topic.

Mina66

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
SFML 2.2 Static linking
« on: December 23, 2014, 05:06:52 pm »
Hello.

Code::Blocks 13.12
 tdm-gcc-4.9.2 32 http://tdm-gcc.tdragon.net/


It is impossible to do static linking. The project settings in here http://www.sfml-dev.org/tutorials/2.2/start-cb.php
Errors
D:\CB_Library\SFML\lib\libsfml-graphics-s-d.a(Texture.cpp.obj)||In function `checkMaximumTextureSize':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\Texture.cpp|64|undefined reference to `glGetIntegerv@8'
|
D:\CB_Library\SFML\lib\libsfml-graphics-s-d.a(Texture.cpp.obj)||In function `ZN2sf7TextureD2Ev':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\Texture.cpp|111|undefined reference to `glDeleteTextures@8'
|
D:\CB_Library\SFML\lib\libsfml-graphics-s-d.a(Texture.cpp.obj)||In function `ZN2sf7Texture6createEjj':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\Texture.cpp|152|undefined reference to `glGenTextures@8'
|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\Texture.cpp|160|undefined reference to `glBindTexture@8'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\Texture.cpp|161|undefined reference to `glTexImage2D@36'
|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\Texture.cpp|162|undefined reference to `glTexParameteri@12'|
...

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: SFML 2.2 Static linking
« Reply #1 on: December 23, 2014, 05:18:17 pm »
You aren't linking all the dependencies.  See http://www.sfml-dev.org/faq.php#build-link-static

notidehunter

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: SFML 2.2 Static linking
« Reply #2 on: December 23, 2014, 05:34:33 pm »
You aren't linking all the dependencies.  See http://www.sfml-dev.org/faq.php#build-link-static

I had some questions about how to do this.  I grabbed the libXXX.a files, some of them came with the SFML binaries I downloaded, others I found in my mingw/lib folder.  I added them to the "Link libraries" list under "Linker Settings".  This is my link order:

sfml-graphics
freetype
glew32
jpeg
sfml-window
opengl32
gdi32
sfml-system
winmm

If I haven't done anything wrong up to this point, my question is this: are there headers for these libraries?  If so, where do I find them?

Note: I'm using mingw 4.7.1.


Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: SFML 2.2 Static linking
« Reply #3 on: December 23, 2014, 05:41:21 pm »
Many of those are Windows-specific libraries so I'd avoid using their headers unless you're sure you need non-portable code (the whole point of SFML is to provide a portable interface on top of this stuff).  For the multi-platform dependencies like OpenGL, GLEW and FreeType, you'll have to google tutorials for whatever library you care about (possibly MinGW-specific ones), since there's no universal convention for this sort of thing, and some of them will have different headers on different platforms.

notidehunter

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: SFML 2.2 Static linking
« Reply #4 on: December 23, 2014, 06:09:44 pm »
What I meant was, do I need to tell Code::Blocks where the headers for those libraries are since SFML uses them?

In other words, following this guide: http://www.sfml-dev.org/tutorials/2.2/start-cb.php

When I want to use the SFML libraries, I add SFML\include to the compiler search directories.  Do I need to do something similar for the dependencies?

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: SFML 2.2 Static linking
« Reply #5 on: December 23, 2014, 06:18:15 pm »
That tutorial assumes you're using pre-built SFML libraries, so the answer is no, you do not need to include the headers of dependencies yourself.  If you were building SFML yourself, you might need to do that (depending on where the headers are and what folders get searched by default).

This is a general property of static linking.  By statically linking SFML, you're saying that you want it and all of its dependencies (sfml-graphics, OpenGL, FreeType, etc) to be a part of the final executable.  This requires that the compiled code for SFML and its dependencies must be linked against when creating that executable, even if you aren't doing the compiling yourself, and even if your code doesn't directly call into those dependencies.

Mina66

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: SFML 2.2 Static linking
« Reply #6 on: December 24, 2014, 03:56:21 am »
Thanks!  :)

notidehunter

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: SFML 2.2 Static linking
« Reply #7 on: December 24, 2014, 04:11:41 am »
Ok that explains it, I was trying to build SFML from source.  Now I've decided that's over my head so I'm using the pre-compiled binaries.  I can build the test project with no errors, but it crashes when I try to run it.  Return value: -1073741510 (0xC0000005). 

I found this SO thread which seems to have a similar problem: http://stackoverflow.com/questions/22368784/sfml-wont-run-in-codeblocks-13-12, but I checked and my compiler (mingw 4.7.1) matches the version of the libraries I downloaded.  Not sure what to do from here.

Edit: here is my build log if that helps.

mingw32-g++.exe -Wall -g -DSFML_STATIC -I..\..\libraries\SFML-2.2-windows-gcc-4.7.1-tdm-32-bit\SFML-2.2\include -c C:\Users\jason\programming\projects\ArtilleryGame\main2.cpp -o obj\Debug\main2.o
mingw32-g++.exe -L..\..\libraries\SFML-2.2-windows-gcc-4.7.1-tdm-32-bit\SFML-2.2\lib -o bin\Debug\ArtilleryGame.exe obj\Debug\main2.o   -lsfml-graphics-s-d -lfreetype -lglew -ljpeg -lsfml-window-s-d -lopengl32 -lgdi32 -lsfml-system-s-d -lwinmm
Output file is bin\Debug\ArtilleryGame.exe with size 3.72 MB
Process terminated with status 0 (0 minute(s), 3 second(s))
0 error(s), 0 warning(s) (0 minute(s), 3 second(s))
« Last Edit: December 24, 2014, 04:13:51 am by notidehunter »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
Re: SFML 2.2 Static linking
« Reply #8 on: December 24, 2014, 11:10:37 am »
You need to add -shared-libgcc and -shared-libstdc++ to your linker settings (see here) or build SFML yourself with the SFML_USE_STATIC_STD_LIBS flag.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

notidehunter

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: SFML 2.2 Static linking
« Reply #9 on: December 24, 2014, 07:52:47 pm »
That didn't seem to fix it, I get the same results.  I tried copying the .dll's into the same folder as the executable, that didn't help either.  Though I noticed I don't have a libgcc.dll, instead there's a libgcc_s_dw2-1.dll and a libgcc_s_sjlj-1.dll.  Not sure if that matters.

Here is the new build log:

mingw32-g++.exe -Wall -g -DSFML_STATIC -I..\..\libraries\SFML-2.2-windows-gcc-4.7.1-tdm-32-bit\SFML-2.2\include -c C:\Users\jason\programming\projects\ArtilleryGame\main2.cpp -o obj\Debug\main2.o
mingw32-g++.exe -L..\..\libraries\SFML-2.2-windows-gcc-4.7.1-tdm-32-bit\SFML-2.2\lib -o bin\Debug\ArtilleryGame.exe obj\Debug\main2.o  -shared-libgcc -shared-libstdc++  -lsfml-graphics-s-d -lfreetype -lglew -ljpeg -lsfml-window-s-d -lopengl32 -lgdi32 -lsfml-system-s-d -lwinmm
Output file is bin\Debug\ArtilleryGame.exe with size 2.81 MB
Process terminated with status 0 (0 minute(s), 1 second(s))
0 error(s), 0 warning(s) (0 minute(s), 1 second(s))

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
AW: SFML 2.2 Static linking
« Reply #10 on: December 24, 2014, 08:06:16 pm »
Can you provide the output you get when you run gcc -v in your compiler directory?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

SpeCter

  • Full Member
  • ***
  • Posts: 151
    • View Profile
Re: SFML 2.2 Static linking
« Reply #11 on: December 24, 2014, 08:17:17 pm »
You should only have one of those two. You can either have dwarf exception handling or sjlj exception handling(or seh).Your compiler should use sjlj by default(32 Bits).

Which package did you download on the frontsite, it looks like you picked the wrong one?
And in one post you said you are using mingw 4.7.1
and before that you say you use 4.9.2?

notidehunter

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: SFML 2.2 Static linking
« Reply #12 on: December 25, 2014, 04:52:32 am »
I'm using mingw 4.7.1.  I'm not the OP (who was using 4.9.2), I just posted in this thread because it seemed related.

Here's the output from gcc -v:

Using built-in specs.
COLLECT_GCC=gcc
Target: mingw32
Configured with: ../../src/gcc-4.7.1/configure --build=mingw32 --enable-languages=c,c++,ada,fortran,objc,obj-c++ --enable-threads=win32 --enable-libgomp --enable-lto --enable-fully-dynamic-string --enable-libstdcxx-debug --enable-version-specific-runtime-libs --with-gnu-ld --disable-nls --disable-win32-registry --disable-symvers --disable-build-poststage1-with-cxx --disable-werror --prefix=/mingw32tdm --with-local-prefix=/mingw32tdm --enable-cxx-flags='-fno-function-sections -fno-data-sections' --with-pkgversion=tdm-1 --enable-sjlj-exceptions --with-bugurl=http://tdm-gcc.tdragon.net/bugs
Thread model: win32
gcc version 4.7.1 (tdm-1)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
AW: SFML 2.2 Static linking
« Reply #13 on: December 25, 2014, 09:06:17 am »
I thought the output would show the wanted information.
So the questions remaining are: What file did you download to get your compiler? And what file did you download to get SFML?
« Last Edit: December 26, 2014, 07:23:09 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

notidehunter

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: SFML 2.2 Static linking
« Reply #14 on: December 25, 2014, 06:12:13 pm »
Compiler is the default one that came with Code::Blocks, codeblocks-13.12mingw-setup.exe from this link: http://www.codeblocks.org/downloads/26#windows

SFML is the "GCC 4.7.1 TDM (SJLJ) - 32-bit" option from here: http://www.sfml-dev.org/download/sfml/2.2/