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

Author Topic: SFML 2.2 on VS2013 - compiled w/ cmake - dynamic works, static doesnt  (Read 2098 times)

0 Members and 1 Guest are viewing this topic.

mbrp

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Not sure what exactly I'm doing wrong.

Specifics:
OS: Win 8.1
Target IDE: VS2013 Update 4
Using cmake 3.1.0 win32 x86 (cmake-gui.exe)
Building from SFML-2.2-sources.zip (downloaded from the website, extracted from zip)

Problem:
Following the Compiling SFML (2.2) with CMake guide, I have successfully built and used the dynamic libraries (BUILD_SHARED_LIBS flag TRUE) both in Release and Debug.  However, when I try to use the static libraries I built, I get LNK2001 and LNK2019 unresolved external symbol errors out the wazoo.

Here are the steps I've taken, with some screenshots:
Ran cmake-gui.exe
Pressed Configure
Selected Visual Studio 12 2013 with 'Use default native compilers'
Adjusted Settings to what they are in the screenshot
Pressed Configure again
Pressed Generate

Opened VS2013
Built the 'ALL_BUILD' project on Release
Built the 'INSTALL' project on Release
Built the 'ALL_BUILD' project on Debug
Built the 'INSTALL' project on Debug

This successfully output all the appropriate .lib files in my SFML\lib folder (note: non -s .libs in this folder were built with the BUILD_SHARED_LIBS flag TRUE and work).

Configured Project Properties > Linker > Additional Dependencies (this screenshot is for debug)
 
And here's the code I'm trying to run (again, works fine with dynamic libraries, but gives linker errors with static libraries):
#include <SFML\Graphics.hpp>

int main()
{
        sf::RenderWindow window(sf::VideoMode(800, 600), "asdf");
       
        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        switch (event.type)
                        {
                        case sf::Event::Closed:
                                window.close();
                                break;
                        case sf::Event::KeyPressed:
                                if (event.key.code == sf::Keyboard::Escape)
                                {
                                        window.close();
                                }
                                break;
                        }
                }

                window.clear();
                window.display();
        }
       
        return 0;
}
 

Sample error:
Quote
Error   1   error LNK2019: unresolved external symbol __imp__glBlendFunc@8 referenced in function "private: void __thiscall sf::RenderTarget::applyBlendMode(struct sf::BlendMode const &)" (?applyBlendMode@RenderTarget@sf@@AAEXABUBlendMode@2@@Z)   E:\cppproj\asdf\asdf\sfml-graphics-s-d.lib(RenderTarget.obj)   asdf

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: SFML 2.2 on VS2013 - compiled w/ cmake - dynamic works, static doesnt
« Reply #1 on: January 25, 2015, 02:10:11 am »
It looks like you may have built correctly but linked incorrectly.
You should read this tutorial that shows how to link with Visual Studio. About half way down, there is a section on static linking. About three quarters of the way down, there is large table. When statically linking, you need to add all of the dependencies manually, not just the modules.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

mbrp

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: SFML 2.2 on VS2013 - compiled w/ cmake - dynamic works, static doesnt
« Reply #2 on: January 25, 2015, 02:28:25 am »
Aha, I see what I did now.  I glossed over the BIG RED BOX that says
Quote
Starting from SFML 2.2, when static linking, you will have to link all of SFML's dependencies to your project as well. This means that if you are linking sfml-window-s.lib or sfml-window-s-d.lib for example, you will also have to link opengl32.lib, winmm.lib and gdi32.lib. Some of these dependency libraries might already be listed under "Inherited values", but adding them again yourself shouldn't cause any problems.
When it came to the part where it had the dependencies listed, I went back and referred to a document I had made back when I built 2.0 for vs2010 some while ago, and just copy-pasted the dependencies from that list rather than verifying whether or not anything had changed.  My bad.

Thank you for pointing it out to me.  I'll fix it and see what happens.

Edit:
That was definitely it.  Working fine now.  Thank you and sorry for not reading more carefully.  :)
« Last Edit: January 25, 2015, 02:36:07 am by mbrp »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: SFML 2.2 on VS2013 - compiled w/ cmake - dynamic works, static doesnt
« Reply #3 on: January 26, 2015, 01:24:38 am »
You're welcome. Glad to help :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything