SFML: Problems with building SFML 3 (and 2.6) on Windows with Clang

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

While I have been constructing a minimal example for another issue (with sf::Strings and wide strings), I noticed there were problems with building SFML 2.6 & 3.0 when using non-MSVC compilers (so MinGW and both Clang-like command-lines (clang-cl.exe & clang++.exe))

Your environment

  • Your OS / distro / window manager used: Windows 10, 64bit, build 21H2 изображение

  • Your version of SFML (2.5.0, git master, etc): 2.6 (branch 2.6.x, tag 3315456dc32e2da000145bb7f97083154806b59b) and 3.0 (branch master, tag 5c9b571c70eeb0171affbce08b005a1d65765115)

  • Your compiler and compiler version used: Clang and MinGW (GNU 11.2.0, bundled with CLion) Clang versions: изображение

  • Special compiler flags used: none

Steps to reproduce

Here is the ZIP archive I used for both text and build tests (the standard is set to C++17): SFMLTest.zip MD5 Checksum: 4c99ca98215ccc919181fd2dd8d24c79

Here is just the main.cpp without any resources:

#include <iostream>
#include <SFML/Graphics.hpp>
int main() {
	sf::RenderWindow window(sf::VideoMode(500, 100), "SFML Wide String Text Example");

	sf::Font font;
	if(!font.loadFromFile("C:\\Windows\\Fonts\\Arial.ttf"))
	{
		std::cerr << "uh oh! (failed loading font)" << std::endl;
		return 1;
	}

	sf::Text text;
	text.setCharacterSize(48);
	text.setString(L"test test тест");
	text.setFont(font);

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

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

Expected behavior

The code compiles successfully and creates a window with a text.

Actual behavior

2.6

MinGW

Compiles successfully (AND works correctly)

MSVC

Compiles successfully (with runtime wide string issues, see Notes)

Clang with MinGW-like command-line

FAILED: _deps/sfml-build/src/SFML/System/CMakeFiles/sfml-system.dir/Clock.cpp.obj 
..\clang++.exe -DSFML_SYSTEM_EXPORTS -I.../SFMLTest/cmake-build-debug/_deps/sfml-src/include -I.../SFMLTest/cmake-build-debug/_deps/sfml-src/src -g -Xclang -gcodeview -O0 -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -std=gnu++17  -Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wcast-align -Wunused -Woverloaded-virtual -Wconversion -Wsign-conversion -Wdouble-promotion -Wformat=2 -Wnull-dereference -Wold-style-cast -Wpedantic -Werror -Wno-unknown-warning-option -MD -MT _deps/sfml-build/src/SFML/System/CMakeFiles/sfml-system.dir/Clock.cpp.obj -MF _deps\sfml-build\src\SFML\System\CMakeFiles\sfml-system.dir\Clock.cpp.obj.d -o _deps/sfml-build/src/SFML/System/CMakeFiles/sfml-system.dir/Clock.cpp.obj -c F:/Projects/CLionProjects/SFMLTest/cmake-build-debug/_deps/sfml-src/src/SFML/System/Clock.cpp
In file included from .../SFMLTest/cmake-build-debug/_deps/sfml-src/src/SFML/System/Clock.cpp:28:
In file included from .../SFMLTest/cmake-build-debug/_deps/sfml-src/include\SFML/System/Clock.hpp:31:
In file included from .../SFMLTest/cmake-build-debug/_deps/sfml-src/include\SFML/System/Export.hpp:31:
.../SFMLTest/cmake-build-debug/_deps/sfml-src/include\SFML/Config.hpp:231:26: error: extension used [-Werror,-Wlanguage-extension-token]
        typedef signed   __int64 Int64;
                         ^
.../SFMLTest/cmake-build-debug/_deps/sfml-src/include\SFML/Config.hpp:232:26: error: extension used [-Werror,-Wlanguage-extension-token]
        typedef unsigned __int64 Uint64;

Clang with MSVC-like command-line

FAILED: _deps/sfml-build/src/SFML/Window/CMakeFiles/sfml-window.dir/Win32/WindowImplWin32.cpp.obj 
...\clang-cl.exe  /nologo -TP -DSFML_WINDOW_EXPORTS -DUNICODE -D_CRT_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -I...\SFMLTest\cmake-build-debug\_deps\sfml-src\include -I...\SFMLTest\cmake-build-debug\_deps\sfml-src\src -I...\SFMLTest\cmake-build-debug\_deps\sfml-src\extlibs\headers\vulkan -imsvc ...\SFMLTest\cmake-build-debug\_deps\sfml-src\extlibs\headers\glad\include -m32 /Zi /Ob0 /Od /RTC1 -MDd -std:c++17  /W4 /w14242 /w14254 /w14263 /w14265 /w14287 /we4289 /w14296 /w14311 /w14545 /w14546 /w14547 /w14549 /w14555 /w14619 /w14640 /w14826 /w14905 /w14906 /w14928 /wd4996 /wd4068 /wd4505 /wd4800 /WX /showIncludes /Fo_deps\sfml-build\src\SFML\Window\CMakeFiles\sfml-window.dir\Win32\WindowImplWin32.cpp.obj /Fd_deps\sfml-build\src\SFML\Window\CMakeFiles\sfml-window.dir\ -c -- ...\SFMLTest\cmake-build-debug\_deps\sfml-src\src\SFML\Window\Win32\WindowImplWin32.cpp
...\SFMLTest\cmake-build-debug\_deps\sfml-src\src\SFML\Window\Win32\WindowImplWin32.cpp(223,147): error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces]
    DEV_BROADCAST_DEVICEINTERFACE deviceInterface = {sizeof(DEV_BROADCAST_DEVICEINTERFACE), DBT_DEVTYP_DEVICEINTERFACE, 0, GUID_DEVINTERFACE_HID, 0};
                                                                                                                                                  ^
                                                                                                                                                  {}
1 error generated.

3.0

MinGW

Compiles, but exits with Process finished with exit code -1073741819 (0xC0000005) The debugger gives points, but gives an exception: Exception: Exception 0xc0000005 encountered at address 0x500e178c: User-mode data execution prevention (DEP) violation at location 0x500e178c

After another rebuild, for whatever reason started working.

MSVC

Compiles successfully (with runtime wide string issues, see Notes)

Clang with MinGW-like command-line

FAILED: _deps/sfml-build/src/SFML/System/CMakeFiles/sfml-system.dir/FileInputStream.cpp.obj 
F:\Apps\LLVM\bin\clang++.exe -DSFML_SYSTEM_EXPORTS -I.../SFMLTest/cmake-build-debug/_deps/sfml-src/include -I.../SFMLTest/cmake-build-debug/_deps/sfml-src/src -g -Xclang -gcodeview -O0 -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -std=gnu++17  -Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wcast-align -Wunused -Woverloaded-virtual -Wconversion -Wsign-conversion -Wdouble-promotion -Wformat=2 -Wimplicit-fallthrough -Wsuggest-override -Wnull-dereference -Wold-style-cast -Wpedantic -Werror -Wno-unknown-warning-option -MD -MT _deps/sfml-build/src/SFML/System/CMakeFiles/sfml-system.dir/FileInputStream.cpp.obj -MF _deps\sfml-build\src\SFML\System\CMakeFiles\sfml-system.dir\FileInputStream.cpp.obj.d -o _deps/sfml-build/src/SFML/System/CMakeFiles/sfml-system.dir/FileInputStream.cpp.obj -c .../SFMLTest/cmake-build-debug/_deps/sfml-src/src/SFML/System/FileInputStream.cpp
.../SFMLTest/cmake-build-debug/_deps/sfml-src/src/SFML/System/FileInputStream.cpp:70:18: error: '_wfopen' is deprecated: This function or variable may be unsafe. Consider using _wfopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [-Werror,-Wdeprecated-declarations]
    m_file.reset(_wfopen(filename.c_str(), L"rb"));
                 ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\corecrt_wstdio.h:132:20: note: '_wfopen' has been explicitly marked deprecated here
    _Check_return_ _CRT_INSECURE_DEPRECATE(_wfopen_s)
                   ^
F:\Apps\VisualStudioBuildTools\VC\Tools\MSVC\14.31.31103\include\vcruntime.h:335:55: note: expanded from macro '_CRT_INSECURE_DEPRECATE'
        #define _CRT_INSECURE_DEPRECATE(_Replacement) _CRT_DEPRECATE_TEXT(    \
                                                      ^
F:\Apps\VisualStudioBuildTools\VC\Tools\MSVC\14.31.31103\include\vcruntime.h:325:47: note: expanded from macro '_CRT_DEPRECATE_TEXT'
#define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
                                              ^
1 error generated.

Clang with MSVC-like command-line

Compiles, but exits with Exception 0xc0000005 encountered at address 0x500e178c: User-mode data execution prevention (DEP) violation at location 0x500e178c. Debugger shows this: изображение

Bonus: MSVC and Clang with MSVC-like command-line with -std:c++latest

3.0

MSVC

#2039

Clang with MSVC-like command-line

Same problem as with C++17 (access violation).

2.6

MSVC

Compiles successfully (with runtime wide string issues, see Notes)

Clang with MSVC-like command-line

Does not have such a flag (??)

Notes

  • I do not use MSYS2 for Clang, it was installed from here.
  • Here is the text issue I mentioned: #2047

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 33 (19 by maintainers)

Most upvoted comments

https://github.com/SFML/SFML/pull/2295

SFML 3 will be getting some Clang.exe CI jobs so we never introduce more of these build issues ever again. We ❤️ our Windows + Clang users.

https://github.com/ChrisThrasher/SFML/actions/runs/3670457670/jobs/6205007134

We’re trying to add a Clang Windows CI job but we’re getting a link error when consuming SFML in static release builds. Perhaps your error was similar? Hopefully we can sort this out but it’s unclear what the cause of the problem is right now.

The link error looked very similar but IIRC didn’t have anything to do with mismatching release/debug configurations. I just tried out to compile the 2.6.x branch from scratch and didn’t have any problems with it so I guess it’s fixed.

With the merging of #2294, I believe all Clang-on-Windows build errors are fixed. I’m going to leave this issue open for a few more days in case we missed something but I believe this issue has been addressed. We hope to add new CI jobs to the pipeline such that future issues don’t creep back into SFML. Sorry for the long time to get this fixed but thanks for reporting it!

I just merged #2293 which should fix the Clang Windows builds for anyone using SFML 3! I’ll see what I can do about fixing it in 2.6.x as well.

Tested it, works, thanks!

Will check in a sec

I submitted #2293 which is a step towards better Windows Clang support. I plan on doing something similar once an GNU-like Clang Windows CI job is added. If someone could build this with GNU-like Clang and let me know what happens, I would really appreciate that.

I’m curious, how are you building SFML? When using the ClangCL frontend we disable that option already, so you must be using Clang in a different way. How exactly?

They’re not using the MSVC-like clang interface, they are using the GNU-like one. The GNU one uses GCC like flags (-Werror) rather than the MSVC style ones (/WX).

I will try and make a PR somewhere this week to disable the deprecated errors to the 2.6.x branch then

Ignore deprecation warnings for now. Use the WARNINGS_AS_ERRORS option to disable warnings as errors so that we can add the new compiler to CI without also having to fix all the new warnings it emits. Once the CI job is in place and merged, then we can think about re-enabling warnings as errors and fixing everything.