SFML: Vector2.inl causing compiler errors with MSVC in VS2022

Thanks for raising your issue here! ๐Ÿ™‚

Before you submit the issue however, weโ€™d like you to consider the follow points.

  • We like to use the issue tracker for confirmed issues.
  • If youโ€™re stuck with SFML, please use the forum to get help.

Subject of the issue

Was attempting to test out changes from the most recent master snapshot of the SFML 3.0 changes and was unable to compile my project. This project I had been using to test some of the 3.0 changes with the previous snapshot build, when I updated to the most recent one and did a clean rebuild I noticed the errors. Another user in the Discord server for SFML also reported the same compilation errors.

include\SFML\System\Vector2.inl(293,41): error C2370: 'sf::Vector2<T>::UnitX': redefinition; different storage class
include\SFML\System\Vector2.hpp(204): message : see declaration of 'sf::Vector2<T>::UnitX'
include\SFML\System\Vector2.inl(296,41): error C2370: 'sf::Vector2<T>::UnitY': redefinition; different storage class
include\SFML\System\Vector2.hpp(205): message : see declaration of 'sf::Vector2<T>::UnitY'

I tried building the SFML from source, then building against the output of that and still the same issues occurred.

Your environment

Microsoft Windows 11 64 Bit SFML 3.0 (occurs with binaries from snapshot taken from master branch on 03/03/2022 & occurs when using binaries built from source) Visual Studio 2022 (VC 17)

Steps to reproduce

  • Setup a project which uses SFML 3.0 within VS2022
  • Set C++ language version of project to C++17
  • Use the source shown below
  • Build and the compiler errors should occur
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(1280, 720), "Minimal, complete and verifiable example");
    window.setFramerateLimit(60);

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

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

Expected behavior

Compilation should complete without errors.

Actual behavior

The following compiler errors are thrown

include\SFML\System\Vector2.inl(293,41): error C2370: 'sf::Vector2<T>::UnitX': redefinition; different storage class
include\SFML\System\Vector2.hpp(204): message : see declaration of 'sf::Vector2<T>::UnitX'
include\SFML\System\Vector2.inl(296,41): error C2370: 'sf::Vector2<T>::UnitY': redefinition; different storage class
include\SFML\System\Vector2.hpp(205): message : see declaration of 'sf::Vector2<T>::UnitY'

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 22 (21 by maintainers)

Most upvoted comments

@Bambo-Borris can you give SFML master another try? It should work fine in permissive mode as well ๐Ÿ™‚

Yeah that has fixed the issue for me, project compiles with the permissive flag set now. Thanks!

I think demoting these constants to non-compiletime constants is our best option for fixing this problem in the short term. That will let us enable /permissive- in the build ensuring that these kinds of problems arenโ€™t reintroduced in the future.

EDIT: CI confirms this works. https://github.com/ChrisThrasher/SFML/actions/runs/2162502305