Context: I'm trying to build the samples in the Vulkan2D repo using the latest version of Visual Studio. Opening the V2D repo in VS2022 and configuring the cmake project works fine, but trying to kick off build of the most basic tutorial (Vulkan2D/examples/main), fails immediately and spectacularly on a bunch of the c files in the VK2D/ directory with errors like these:
>------ Build started: Project: CMakeLists, Configuration: Debug ------
[1/19] Building C object examples\main\CMakeFiles\main.dir\__\__\VK2D\Image.c.obj
FAILED: examples/main/CMakeFiles/main.dir/__/__/VK2D/Image.c.obj
C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1435~1.322\bin\Hostx64\x64\cl.exe /nologo -IZ:\repos\git\github.com\PaoloMazzon\Vulkan2D\examples\main\..\.. -IZ:\Vulkan\Vulkan-1.3.243.0\Include -external:IZ:\repos\git\github.com\vcpkg\installed\x64-windows\include\SDL2 -external:IZ:\repos\git\github.com\vcpkg\installed\x64-windows\include -external:W0 /DWIN32 /D_WINDOWS /Zi /Ob0 /Od /RTC1 -MDd -std:c11 /showIncludes /Foexamples\main\CMakeFiles\main.dir\__\__\VK2D\Image.c.obj /Fdexamples\main\CMakeFiles\main.dir\ /FS -c Z:\repos\git\github.com\PaoloMazzon\Vulkan2D\VK2D\Image.c
Z:\repos\git\github.com\PaoloMazzon\Vulkan2D\VK2D\Opaque.h(36): error C2061: syntax error: identifier '_Atomic'
Z:\repos\git\github.com\PaoloMazzon\Vulkan2D\VK2D\Opaque.h(40): error C2061: syntax error: identifier 'quitThread'
Z:\repos\git\github.com\PaoloMazzon\Vulkan2D\VK2D\Opaque.h(40): error C2059: syntax error: ';'
Z:\repos\git\github.com\PaoloMazzon\Vulkan2D\VK2D\Opaque.h(41): error C2061: syntax error: identifier 'loads'
Z:\repos\git\github.com\PaoloMazzon\Vulkan2D\VK2D\Opaque.h(41): error C2059: syntax error: ';'
Z:\repos\git\github.com\PaoloMazzon\Vulkan2D\VK2D\Opaque.h(42): error C2061: syntax error: identifier 'doneLoading'
Z:\repos\git\github.com\PaoloMazzon\Vulkan2D\VK2D\Opaque.h(42): error C2059: syntax error: ';'
Z:\repos\git\github.com\PaoloMazzon\Vulkan2D\VK2D\Opaque.h(44): error C2059: syntax error: '}'
Z:\repos\git\github.com\PaoloMazzon\Vulkan2D\VK2D\Image.c(136): error C2037: left of 'dev' specifies undefined struct/union 'VK2DLogicalDevice_t'
Z:\repos\git\github.com\PaoloMazzon\Vulkan2D\VK2D\Image.c(136): warning C4133: 'function': incompatible types - from 'VkImageViewCreateInfo *' to 'VkDevice'
Z:\repos\git\github.com\PaoloMazzon\Vulkan2D\VK2D\Image.c(136): warning C4047: 'function': 'const VkAllocationCallbacks *' differs in levels of indirection from 'VkImageView *'
Z:\repos\git\github.com\PaoloMazzon\Vulkan2D\VK2D\Image.c(136): warning C4024: 'vkCreateImageView': different types for formal and actual parameter 3
Z:\repos\git\github.com\PaoloMazzon\Vulkan2D\VK2D\Image.c(136): error C2198: 'vkCreateImageView': too few arguments for call
Z:\repos\git\github.com\PaoloMazzon\Vulkan2D\VK2D\Image.c(221): error C2037: left of 'dev' specifies undefined struct/union 'VK2DLogicalDevice_t'
Z:\repos\git\github.com\PaoloMazzon\Vulkan2D\VK2D\Image.c(221): warning C4133: 'function': incompatible types - from 'VkImageView' to 'VkDevice'
Z:\repos\git\github.com\PaoloMazzon\Vulkan2D\VK2D\Image.c(221): error C2198: 'vkDestroyImageView': too few arguments for call
So, my naive guess on this is that there's something wrong with how the c11 (or c11 atomics?) support flag is being passed down the build toolchain from VS2022 -> cmake -> ninja -> cl.exe correctly so that cl.exe is not able to parse the source (which is using c11 atomics).
I tried to confirm this by going to the repo root and running the following command (note the first two flags, the first of which was being correctly passed by ninja when kicking off the build from VS2022):
cl.exe ^
-std:c11 ^
-experimental:c11atomics ^
-Foexamples\main\CMakeFiles\main.dir\VK2D\Buffer.c.obj ^
-Fdexamples\main\CMakeFiles\main.dir\ ^
-I. ^
-IZ:\Vulkan\Vulkan-1.3.243.0\Include ^
-IZ:\repos\git\github.com\vcpkg\installed\x64-windows\include\SDL2 ^
-IZ:\repos\git\github.com\vcpkg\installed\x64-windows\include ^
-c Z:\repos\git\github.com\PaoloMazzon\Vulkan2D\VK2D\Buffer.c
This compiles fine. So, it seems like I need to get the -experimental:c11atomics flag on the cl.exe command line to progress with my build, but with a couple of hours of Googling around various combinations of the keywords in this post, I can't find where to add this additional command line flag in VS2022.
A couple more hours of futzing around, and I found the solution, although it was very hard to find given the search terms I had:
Go to the
CMake SettingsinVS2022, scroll down to theCMake variables and cachesection, and above the list of variables, check theShow advanced variablesbox. Now, you have access to a set ofCMAKE_<LANG>_FLAGSvaraiables where you can add additional flags for each compiler, for each language, and for each build target. In my case, I needed to append/experimental:c11atomicsto the variableCMAKE_C_FLAGS.Hope this helps someone else who can't figure out how to populate this flag when using this build toolchain in Visual Studio.