SFML - Statically Linking Libraries

Pages: 12
I've been struggling to get SFML set up using the statically linked libraries for the past couple of hours.

I'm using Code::Blocks, and at the moment I have it set up so that both the debug and release versions of the modules are linked under Project -> Build options -> Linker settings. The include and lib directories are added under Search directories and SFML_STATIC has been typed in #defines.

I'm using the example code from the SFML tutorial:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}


The errors I'm getting are:
||=== Build: Debug in SFML (compiler: GNU GCC Compiler) ===|
..\..\..\..\SFML-2.3\lib\libsfml-graphics-s-d.a(RenderWindow.cpp.obj)||In function `ZNK2sf12RenderWindow7captureEv':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderWindow.cpp|92|undefined reference to `glReadPixels@28'|
..\..\..\..\SFML-2.3\lib\libsfml-graphics-s-d.a(RenderTarget.cpp.obj)||In function `ZN2sf12RenderTarget5clearERKNS_5ColorE':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|97|undefined reference to `glClearColor@16'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|98|undefined reference to `glClear@4'|
..\..\..\..\SFML-2.3\lib\libsfml-graphics-s-d.a(RenderTarget.cpp.obj)||In function `ZN2sf12RenderTarget4drawEPKNS_6VertexEjNS_13PrimitiveTypeERKNS_12RenderStatesE':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|267|undefined reference to `glVertexPointer@16'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|268|undefined reference to `glColorPointer@16'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|269|undefined reference to `glTexCoordPointer@16'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|278|undefined reference to `glDrawArrays@12'|
..\..\..\..\SFML-2.3\lib\libsfml-graphics-s-d.a(RenderTarget.cpp.obj)||In function `ZN2sf12RenderTarget12pushGLStatesEv':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|297|undefined reference to `glGetError@0'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|307|undefined reference to `glPushClientAttrib@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|308|undefined reference to `glPushAttrib@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|310|undefined reference to `glMatrixMode@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|311|undefined reference to `glPushMatrix@0'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|312|undefined reference to `glMatrixMode@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|313|undefined reference to `glPushMatrix@0'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|314|undefined reference to `glMatrixMode@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|315|undefined reference to `glPushMatrix@0'|
..\..\..\..\SFML-2.3\lib\libsfml-graphics-s-d.a(RenderTarget.cpp.obj)||In function `ZN2sf12RenderTarget11popGLStatesEv':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|327|undefined reference to `glMatrixMode@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|328|undefined reference to `glPopMatrix@0'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|329|undefined reference to `glMatrixMode@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|330|undefined reference to `glPopMatrix@0'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|331|undefined reference to `glMatrixMode@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|332|undefined reference to `glPopMatrix@0'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|334|undefined reference to `glPopClientAttrib@0'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|335|undefined reference to `glPopAttrib@0'|
..\..\..\..\SFML-2.3\lib\libsfml-graphics-s-d.a(RenderTarget.cpp.obj)||In function `ZN2sf12RenderTarget13resetGLStatesEv':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|360|undefined reference to `glDisable@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|361|undefined reference to `glDisable@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|362|undefined reference to `glDisable@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|363|undefined reference to `glDisable@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|364|undefined reference to `glEnable@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|365|undefined reference to `glEnable@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|366|undefined reference to `glMatrixMode@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|367|undefined reference to `glEnableClientState@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|368|undefined reference to `glEnableClientState@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|369|undefined reference to `glEnableClientState@4'|
..\..\..\..\SFML-2.3\lib\libsfml-graphics-s-d.a(RenderTarget.cpp.obj)||In function `ZN2sf12RenderTarget16applyCurrentViewEv':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|405|undefined reference to `glViewport@16'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|408|undefined reference to `glMatrixMode@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|409|undefined reference to `glLoadMatrixf@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|412|undefined reference to `glMatrixMode@4'|
..\..\..\..\SFML-2.3\lib\libsfml-graphics-s-d.a(RenderTarget.cpp.obj)||In function `ZN2sf12RenderTarget14applyBlendModeERKNS_9BlendModeE':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|430|undefined reference to `glBlendFunc@8'|
..\..\..\..\SFML-2.3\lib\libsfml-graphics-s-d.a(RenderTarget.cpp.obj)||In function `ZN2sf12RenderTarget14applyTransformERKNS_9TransformE':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|471|undefined reference to `glLoadMatrixf@4'|
..\..\..\..\SFML-2.3\lib\libsfml-graphics-s-d.a(GLCheck.cpp.obj)||In function `ZN2sf4priv12glCheckErrorEPKcj':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\GLCheck.cpp|40|undefined reference to `glGetError@0'|
..\..\..\..\SFML-2.3\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'|
..\..\..\..\SFML-2.3\lib\libsfml-graphics-s-d.a(Texture.cpp.obj)||In function `ZN2sf7TextureD2Ev':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\Texture.cpp|110|undefined reference to `glDeleteTextures@8'|
..\..\..\..\SFML-2.3\lib\libsfml-graphics-s-d.a(Texture.cpp.obj)||In function `ZN2sf7Texture6createEjj':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\Texture.cpp|151|undefined reference to `glGenTextures@8'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\Texture.cpp|176|undefined reference to `glBindTexture@8'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\Texture.cpp|177|undefined reference to `glTexImage2D@36'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\Texture.cpp|178|undefined reference to `glTexParameteri@12'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\Texture.cpp|179|undefined reference to `glTexParameteri@12'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\Texture.cpp|180|undefined reference to `glTexParameteri@12'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\Texture.cpp|181|undefined reference to `glTexParameteri@12'|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build failed: 50 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

It works fine when the modules are dynamically linked, but I don't want have to add the libraries to every project I may wish to create.

I'd appreciate if someone helped me with this, it's kinda frustrating.
Did you link modules in correct order? And did you link dependencies for these modules?
http://www.sfml-dev.org/faq.php#build-link-static
This might help. I can't edit my original post for some reason.

||=== Build: Debug in SFML (compiler: GNU GCC Compiler) ===|
..\..\..\..\SFML-2.3\lib\libsfml-graphics-s-d.a(RenderWindow.cpp.obj)||In function `ZNK2sf12RenderWindow7captureEv':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderWindow.cpp|92|undefined reference to `glReadPixels@28'|
..\..\..\..\SFML-2.3\lib\libsfml-graphics-s-d.a(RenderTarget.cpp.obj)||In function `ZN2sf12RenderTarget5clearERKNS_5ColorE':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|97|undefined reference to `glClearColor@16'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|98|undefined reference to `glClear@4'|
..\..\..\..\SFML-2.3\lib\libsfml-graphics-s-d.a(RenderTarget.cpp.obj)||In function `ZN2sf12RenderTarget4drawEPKNS_6VertexEjNS_13PrimitiveTypeERKNS_12RenderStatesE':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|267|undefined reference to `glVertexPointer@16'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|268|undefined reference to `glColorPointer@16'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|269|undefined reference to `glTexCoordPointer@16'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|278|undefined reference to `glDrawArrays@12'|
..\..\..\..\SFML-2.3\lib\libsfml-graphics-s-d.a(RenderTarget.cpp.obj)||In function `ZN2sf12RenderTarget12pushGLStatesEv':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|297|undefined reference to `glGetError@0'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|307|undefined reference to `glPushClientAttrib@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|308|undefined reference to `glPushAttrib@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|310|undefined reference to `glMatrixMode@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|311|undefined reference to `glPushMatrix@0'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|312|undefined reference to `glMatrixMode@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|313|undefined reference to `glPushMatrix@0'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|314|undefined reference to `glMatrixMode@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|315|undefined reference to `glPushMatrix@0'|
..\..\..\..\SFML-2.3\lib\libsfml-graphics-s-d.a(RenderTarget.cpp.obj)||In function `ZN2sf12RenderTarget11popGLStatesEv':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|327|undefined reference to `glMatrixMode@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|328|undefined reference to `glPopMatrix@0'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|329|undefined reference to `glMatrixMode@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|330|undefined reference to `glPopMatrix@0'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|331|undefined reference to `glMatrixMode@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|332|undefined reference to `glPopMatrix@0'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|334|undefined reference to `glPopClientAttrib@0'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|335|undefined reference to `glPopAttrib@0'|
..\..\..\..\SFML-2.3\lib\libsfml-graphics-s-d.a(RenderTarget.cpp.obj)||In function `ZN2sf12RenderTarget13resetGLStatesEv':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|360|undefined reference to `glDisable@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|361|undefined reference to `glDisable@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|362|undefined reference to `glDisable@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|363|undefined reference to `glDisable@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|364|undefined reference to `glEnable@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|365|undefined reference to `glEnable@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|366|undefined reference to `glMatrixMode@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|367|undefined reference to `glEnableClientState@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|368|undefined reference to `glEnableClientState@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|369|undefined reference to `glEnableClientState@4'|
..\..\..\..\SFML-2.3\lib\libsfml-graphics-s-d.a(RenderTarget.cpp.obj)||In function `ZN2sf12RenderTarget16applyCurrentViewEv':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|405|undefined reference to `glViewport@16'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|408|undefined reference to `glMatrixMode@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|409|undefined reference to `glLoadMatrixf@4'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|412|undefined reference to `glMatrixMode@4'|
..\..\..\..\SFML-2.3\lib\libsfml-graphics-s-d.a(RenderTarget.cpp.obj)||In function `ZN2sf12RenderTarget14applyBlendModeERKNS_9BlendModeE':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|430|undefined reference to `glBlendFunc@8'|
..\..\..\..\SFML-2.3\lib\libsfml-graphics-s-d.a(RenderTarget.cpp.obj)||In function `ZN2sf12RenderTarget14applyTransformERKNS_9TransformE':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\RenderTarget.cpp|471|undefined reference to `glLoadMatrixf@4'|
..\..\..\..\SFML-2.3\lib\libsfml-graphics-s-d.a(GLCheck.cpp.obj)||In function `ZN2sf4priv12glCheckErrorEPKcj':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\GLCheck.cpp|40|undefined reference to `glGetError@0'|
..\..\..\..\SFML-2.3\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'|
..\..\..\..\SFML-2.3\lib\libsfml-graphics-s-d.a(Texture.cpp.obj)||In function `ZN2sf7TextureD2Ev':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\Texture.cpp|110|undefined reference to `glDeleteTextures@8'|
..\..\..\..\SFML-2.3\lib\libsfml-graphics-s-d.a(Texture.cpp.obj)||In function `ZN2sf7Texture6createEjj':|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\Texture.cpp|151|undefined reference to `glGenTextures@8'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\Texture.cpp|176|undefined reference to `glBindTexture@8'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\Texture.cpp|177|undefined reference to `glTexImage2D@36'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\Texture.cpp|178|undefined reference to `glTexParameteri@12'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\Texture.cpp|179|undefined reference to `glTexParameteri@12'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\Texture.cpp|180|undefined reference to `glTexParameteri@12'|
D:\sfml-release\_Sources\SFML\src\SFML\Graphics\Texture.cpp|181|undefined reference to `glTexParameteri@12'|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build failed: 50 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
The order I added the modules was graphics -> audio -> network -> window -> system. I don't think I added any dependencies, at least not explicitly. How would I do that?
Yeah. Function names says that OpenGL is not linked to your project.
You link dependencies the same way you link other libraries. Just make sure that they are before libraries using them in link order.
FAQ link contains link where you can get those dependencies.
I checked and I have all of the dependencies except for winmm, gdi32, opengl32 and ws2_32. I can't find those in the GitHub directories though.
All those libraries should be already in your compiler instalation. Try to just add them. (those are system libraries)
Should I keep the full file path for the dependencies or shorten them to just their names like the SFML modules?
Like you want. I prefer shortened ways.
I've added all the dependencies but the same errors are still coming up. Do you know what else I might try?
1) Order does matter. Are you sure that opengl32 is linked before anything else?
Yes, opengl32 is first in both debug and release. Would you like me to list the order the dependencies are linked in?
Last edited on
When you press "build", C::B shows command line, like this http://puu.sh/iWK3O/39e6210ecc.png
Check if library are in correct order in command lin.
I'm not very good at using the command line. How would I check to see if the libraries are in the correct order using it?
From experience, the dependencies for SFML in codeblocks must be linked after the SFML libraries.
All the SFML modules first, then all the dependencies after?
That's how I do it and it's always worked for me. I usually do the dependencies in the order of the libraries that depend on them (those required by graphics, then those required by audio, then those required by network, then those required by window and finally those required by system).
Okay, I'll give it a try.
That worked for the project I was working in. However I set up another project to see if it would work again and it doesn't. I must be doing something wrong, because the whole point of statically linking the libraries is so that you don't need to set them up again for every single project, isn't it?
No, the point of statically linking is that you don't need to distribute all the dlls with your program. If you want to avoid linking every new project try creating a project template (I think that's what it's called).
Last edited on
Pages: 12