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

Author Topic: SFML installed from vcpkg fails to link statically  (Read 651 times)

0 Members and 1 Guest are viewing this topic.

andreasxp

  • Newbie
  • *
  • Posts: 0
    • View Profile
SFML installed from vcpkg fails to link statically
« on: November 20, 2019, 05:28:50 pm »
When installing SFML from the vcpkg package manager, static linking fails.
I have opened an issue on vcpkg github https://github.com/microsoft/vcpkg/issues/8864, but it seems that it does not get much attention.

I want to post it here in case anyone has encountered this problem and can contribute. Seems like a pretty big issue to me.
I will copy the issue below:

Description
When building a "hello world" program with sfml and visual studio (configured to use static triplets), build fails on link step. It seems that vcpkg does not define `SFML_STATIC`, which is required for static builds. But even after defining it manually linking still fails (build log below). Dynamic SFML builds fine.

Environment
- OS: Windows 10 Education (ver. 1903).
- Locale: ru-RU
- Successfully installed `sfml:x86-windows`, `sfml:x64-windows`, `sfml:x86-windows-static`, `sfml:x64-windows-static`
- Visual studio 2019 16.3.7
- Project file modified to include these lines:

<PropertyGroup Label="Globals">
  ...
  <VcpkgTriplet Condition="'$(Platform)'=='Win32'">x86-windows-static</VcpkgTriplet>
  <VcpkgTriplet Condition="'$(Platform)'=='x64'">x64-windows-static</VcpkgTriplet>
</PropertyGroup>


To Reproduce
Steps to reproduce the behavior:
1. integrate vcpkg with visual studio as per tutorial.
2. ./vcpkg install sfml:x86-windows-static sfml:x64-windows-static
3. Create a project, modify the project file as specified above, set library switches to /MTd and /MT for debug and release
4. Copy and paste this example code:

#define SFML_STATIC // This is a bug by itself - shouldn't vcpkg define this for me?
#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;
}

5. Build and observe linking errors.

Failure logs
This is a build log with normal verbosity, building x86 debug application and manually defining `SFML_STATIC`:

1>------ Build started: Project: Test Project (Static Linking), Configuration: Debug Win32 ------
1>Build started 03.11.19 02:21:59.
1>Target InitializeBuildStatus:
1>  Touching "Debug\Test Pro.75f51cad.tlog\unsuccessfulbuild".
1>Target VcpkgTripletSelection:
1>  Using triplet "x86-windows-static" from "C:\Users\andreasxp\vcpkg\installed\x86-windows-static\"
1>Target ClCompile:
1>  main.cpp
1>Target Link:
1>  sfml-window-s-d.lib(JoystickImpl.cpp.obj) : error LNK2019: unresolved external symbol __imp__joyGetPosEx@8 referenced in function "public: static bool __cdecl sf::priv::JoystickImpl::isConnected(unsigned int)" (?isConnected@JoystickImpl@priv@sf@@SA_NI@Z)
1>  sfml-window-s-d.lib(JoystickImpl.cpp.obj) : error LNK2019: unresolved external symbol __imp__joyGetDevCapsW@12 referenced in function "public: bool __thiscall sf::priv::JoystickImpl::open(unsigned int)" (?open@JoystickImpl@priv@sf@@QAE_NI@Z)
1>  sfml-system-s-d.lib(SleepImpl.cpp.obj) : error LNK2019: unresolved external symbol __imp__timeGetDevCaps@8 referenced in function "void __cdecl sf::priv::sleepImpl(class sf::Time)" (?sleepImpl@priv@sf@@YAXVTime@2@@Z)
1>  sfml-system-s-d.lib(SleepImpl.cpp.obj) : error LNK2019: unresolved external symbol __imp__timeBeginPeriod@4 referenced in function "void __cdecl sf::priv::sleepImpl(class sf::Time)" (?sleepImpl@priv@sf@@YAXVTime@2@@Z)
1>  sfml-system-s-d.lib(SleepImpl.cpp.obj) : error LNK2019: unresolved external symbol __imp__timeEndPeriod@4 referenced in function "void __cdecl sf::priv::sleepImpl(class sf::Time)" (?sleepImpl@priv@sf@@YAXVTime@2@@Z)
1>  D:\Files\Develop\VS Projects\Test Project (Static Linking)\Debug\Test Project (Static Linking).exe : fatal error LNK1120: 5 unresolved externals
1>Done building target "Link" in project "Test Project (Static Linking).vcxproj" -- FAILED.
1>
1>Done building project "Test Project (Static Linking).vcxproj" -- FAILED.
1>
1>Build FAILED.
1>
1>sfml-window-s-d.lib(JoystickImpl.cpp.obj) : error LNK2019: unresolved external symbol __imp__joyGetPosEx@8 referenced in function "public: static bool __cdecl sf::priv::JoystickImpl::isConnected(unsigned int)" (?isConnected@JoystickImpl@priv@sf@@SA_NI@Z)
1>sfml-window-s-d.lib(JoystickImpl.cpp.obj) : error LNK2019: unresolved external symbol __imp__joyGetDevCapsW@12 referenced in function "public: bool __thiscall sf::priv::JoystickImpl::open(unsigned int)" (?open@JoystickImpl@priv@sf@@QAE_NI@Z)
1>sfml-system-s-d.lib(SleepImpl.cpp.obj) : error LNK2019: unresolved external symbol __imp__timeGetDevCaps@8 referenced in function "void __cdecl sf::priv::sleepImpl(class sf::Time)" (?sleepImpl@priv@sf@@YAXVTime@2@@Z)
1>sfml-system-s-d.lib(SleepImpl.cpp.obj) : error LNK2019: unresolved external symbol __imp__timeBeginPeriod@4 referenced in function "void __cdecl sf::priv::sleepImpl(class sf::Time)" (?sleepImpl@priv@sf@@YAXVTime@2@@Z)
1>sfml-system-s-d.lib(SleepImpl.cpp.obj) : error LNK2019: unresolved external symbol __imp__timeEndPeriod@4 referenced in function "void __cdecl sf::priv::sleepImpl(class sf::Time)" (?sleepImpl@priv@sf@@YAXVTime@2@@Z)
1>D:\Files\Develop\VS Projects\Test Project (Static Linking)\Debug\Test Project (Static Linking).exe : fatal error LNK1120: 5 unresolved externals
1>    0 Warning(s)
1>    6 Error(s)
1>
1>Time Elapsed 00:00:01.05
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Additional context
Digging around in SFML, I found out that sfml-system requires winmm library for joystick support. Maybe this library is not linked properly, which is causing joystick-related linking errors. I do not know what's causing the sleep-related errors.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 9573
    • View Profile
    • development blog
    • Email
Re: SFML installed from vcpkg fails to link statically
« Reply #1 on: November 20, 2019, 10:39:07 pm »
All the unresolved symbols are part of winmm, which would mean winmm isn't being linked.

winmm needs to be linked against your application. I don't know enough about vcpkg to tell where you'd specify it, so it gets automatically linked, but I left some (hopefully) useful comments on the issue and I might ping someone who previously did some work on it and knows a bit more about vcpkg.
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 9573
    • View Profile
    • development blog
    • Email
Re: SFML installed from vcpkg fails to link statically
« Reply #2 on: November 21, 2019, 01:22:05 am »
I discussed with someone on the cpplang Slack and after various CMake focused discussion, it seems that since you presumably use the VS integration (as you didn't provide a CMakeLists.txt file), you have to manually add system libraries, such as winmm.lib (and potentially gdi32.lib).

See also their comment on GitHub.
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/