Compiling the tutorial hello triangle with MSYS2 on windows 10

I used the command:
g++ -std=c++17 -o triangle 15_hello_triangle.cpp -lglfw3 -lvulkan -lwinmm -lgdi32 -Wl,--subsystem,windows
and it compiles and links without any error or warning messages, but when I run it, the program blank window splashes and on the console I get the message:
failed to create window surface!

Any help with what is the cause is appreciated, no I haven’t edited the source just copy paste verbatim from the web site…

Well, I modified the code as follows (the function createSurface), replaced glfwCreateWindowSurface by its implementation for windows mentioned in the tutorial so it became:

void createSurface() {
	VkWin32SurfaceCreateInfoKHR createInfo = {};
	createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
	createInfo.hwnd = glfwGetWin32Window(window);
	createInfo.hinstance = GetModuleHandle(nullptr);
	if (vkCreateWin32SurfaceKHR(instance, &createInfo, nullptr,
		&surface) != VK_SUCCESS) {
			throw std::runtime_error("failed to create window surface!");		
    //if (glfwCreateWindowSurface(instance, window, nullptr, &surface) != VK_SUCCESS) {
      //  throw std::runtime_error("failed to create window surface!");
    }
}

And of course added the necessary heading:

#define GLFW_EXPOSE_NATIVE_WIN32
#include <GLFW/glfw3native.h>
#include <vulkan/vulkan_win32.h>

et voila the triangle appears in the window.

I am still wondering is this a bug in glfw and is it just for windows or also on mac and linux. Is there a better way around it? is there a patch that fixes it.

and just trying both versions on Microsoft Visual studio Community 2017 neither work.
I had to get over complaining about std::optional with a primitive type as template parameter from Microsoft compiler to get it to compile. Anyone was able to get the tutorial example working (either version) on Visual studio.

The program I am talking about is C++ and is presented in this site:
https://vulkan-tutorial.com/
Hope you can give it a try and let me know…

In Cygwin or whatever linuxy shell you are using, try -mwin32, or define the Windows predefined macros yourself.

I assume stuff just works in VS, but I am not at PC rn. Besides you should contact the author of the sample if it doesn’t.

Well here is another cpp program that has the same issue. I don’t think this problem is specific to this one cpp program which is well written and clear enough. I believe that it has to do with dealing with cpp that glfwCreateWindowSurface has an issue. If you go to this link:

http://www.sumantaguha.com/downloads

and download the squareVulkanized program, a program written by the author of an opengl textbook that illustrates vulkan by drawing a static square to compare it with opengl…
It has the exact same problem as the hello triangle program in the tutorial. First this program gives a segmentation fault, and upon replacing glfwCreateWindowSurface by the same exact code that I used in the working version of hello triangle in mingw64, the program runs fine…
It could be nasty problems with pointers when switching between C and C++ or whatever in glfwCreateWindowSurface. Anyway I posted my message in glfw forum and got some replies but not much of help either…I don’t have access to Mac or Linux machines (I need windows for better Arabic support for my professional work rather than Linux), and posted on the hope that someone with such access would try and let me know…

Well, what’s your GLGW version?

I presume you are asking for GLFW version. It is the latest release, just download it and build it for VS for the squarevulkanized program that runs in VS. In MSYS2 it is up to date to 3.2

Well after replying I checked the GLFW site and found a new release 3.3, will try it then…

Actually not I had the right version 3.3.2, I was mistaken thinking it is 3.2. So I have the latest release that I used all along

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.