# GLFW on MSYS2 on Windows 10 and vulkan

**URL:** <https://discourse.glfw.org/t/glfw-on-msys2-on-windows-10-and-vulkan/1529>\
**Category:** support\
**Created:** [April 9, 2020, 9:36pm UTC](https://discourse.glfw.org/t/glfw-on-msys2-on-windows-10-and-vulkan/1529 "2020-04-09T21:36:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![HishamMSueyllam](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/hishammsueyllam/32/324_2.png) [@HishamMSueyllam](https://discourse.glfw.org/u/HishamMSueyllam)\
**Post date:** [April 9, 2020, 9:36pm UTC](https://discourse.glfw.org/t/glfw-on-msys2-on-windows-10-and-vulkan/1529/1 "2020-04-09T21:36:39Z")

</div>

I posted the following 2 messages on the Khronos basic coding forum and got no reply so far. May be this is a better place to get a reply. Here is the first message:  
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…

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![HishamMSueyllam](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/hishammsueyllam/32/324_2.png) [@HishamMSueyllam](https://discourse.glfw.org/u/HishamMSueyllam)\
**Post date:** [April 10, 2020, 6:27am UTC](https://discourse.glfw.org/t/glfw-on-msys2-on-windows-10-and-vulkan/1529/2 "2020-04-10T06:27:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [April 10, 2020, 9:07am UTC](https://discourse.glfw.org/t/glfw-on-msys2-on-windows-10-and-vulkan/1529/3 "2020-04-10T09:07:28Z")

</div>

Hi and welcome to the GLFW forums!

I don’t know what tutorial you are referencing, but the [triangle-vulkan.c](https://github.com/glfw/glfw/blob/master/tests/triangle-vulkan.c) in the GLFW test folder compiles and runs fine for me with Visual Studio 2019 on Windows 10.

You might find it useful to compile and run that example as a starting point. The easiest approach to compiling is to use cmake to generate the GLFW.sln project file for visual studio and then open that, set the startup project to triangle-vulkan in the GLFW/Tests folder and build & run that.

Cheers,

Doug.

---

<div class="post-metadata">

**Author:** ![HishamMSueyllam](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/hishammsueyllam/32/324_2.png) [@HishamMSueyllam](https://discourse.glfw.org/u/HishamMSueyllam)\
**Post date:** [April 10, 2020, 10:53am UTC](https://discourse.glfw.org/t/glfw-on-msys2-on-windows-10-and-vulkan/1529/4 "2020-04-10T10:53:27Z")

</div>

Thanks for the reply. I’ll give your program a try but that’s C and not C++ and I don’t know yet why use glad.  
The program I am talking about is C++ and is presented in this site: [https://vulkan-tutorial.com/](https://vulkan-tutorial.com/)  
Hope you can give it a try and let me know…

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [April 10, 2020, 11:30am UTC](https://discourse.glfw.org/t/glfw-on-msys2-on-windows-10-and-vulkan/1529/5 "2020-04-10T11:30:36Z")

</div>

Hi,

I’m not willing to investigate and debug someone else’s tutorial - perhaps use the comment section to ask the author directly?

GLFW has a C API, so using the C program to check you can run GLFW with Vulkan is a very sensible approach. If you can build and run triangle-vulkan.c and it works properly then this will help you debug what’s going on as we will know that that version of GLFW works with Vulkan on your machine.

Cheers,

Doug.

---

<div class="post-metadata">

**Author:** ![HishamMSueyllam](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/hishammsueyllam/32/324_2.png) [@HishamMSueyllam](https://discourse.glfw.org/u/HishamMSueyllam)\
**Post date:** [April 10, 2020, 12:35pm UTC](https://discourse.glfw.org/t/glfw-on-msys2-on-windows-10-and-vulkan/1529/6 "2020-04-10T12:35:26Z")

</div>

Well the C program is 2230 line of code while the C++ is 920 line. It is much easier for a beginner to learn and understand the C++ program than the C that in addition needs an extra package glad. Also as I understand C++ is almost a super set of C, they are related…

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [April 10, 2020, 12:47pm UTC](https://discourse.glfw.org/t/glfw-on-msys2-on-windows-10-and-vulkan/1529/7 "2020-04-10T12:47:57Z")

</div>

I think you are misunderstanding me.

I am not proposing that you use the triangle-vulkan.c program as a tutorial.

I am proposing that you build and run it - if you have a problem with it then we know there is an issue with GLFW on your system.

---

<div class="post-metadata">

**Author:** ![HishamMSueyllam](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/hishammsueyllam/32/324_2.png) [@HishamMSueyllam](https://discourse.glfw.org/u/HishamMSueyllam)\
**Post date:** [April 10, 2020, 5:06pm UTC](https://discourse.glfw.org/t/glfw-on-msys2-on-windows-10-and-vulkan/1529/8 "2020-04-10T17:06:46Z")

</div>

OK, so I tried the test triangle-vulkan.c to make sure of my version of glfw3, but it needs glad/vulkan.h so I set up git to set up vcpckg to set up glad. But I only have glad.h in the include subdir and in the help of the glad.exe it mentions opengl only and there is no mention of vulkan and no vulkan.h, so I am stuck.

---

<div class="post-metadata">

**Author:** ![HishamMSueyllam](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/hishammsueyllam/32/324_2.png) [@HishamMSueyllam](https://discourse.glfw.org/u/HishamMSueyllam)\
**Post date:** [April 10, 2020, 5:19pm UTC](https://discourse.glfw.org/t/glfw-on-msys2-on-windows-10-and-vulkan/1529/9 "2020-04-10T17:19:51Z")

</div>

Another thing I don’t understand is that the installation that vcpkg created besides lacking the vulkan.h file, it says x86-windows so is it for 32-bit platform and those glad.lib are 32-bits. I am using a 64-bit platform and downloaded a 64-bit git, so how do I get glad.lib for 64 bit and also is the glad.h fine for 64-bit platform.

---

<div class="post-metadata">

**Author:** ![HishamMSueyllam](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/hishammsueyllam/32/324_2.png) [@HishamMSueyllam](https://discourse.glfw.org/u/HishamMSueyllam)\
**Post date:** [April 10, 2020, 6:16pm UTC](https://discourse.glfw.org/t/glfw-on-msys2-on-windows-10-and-vulkan/1529/10 "2020-04-10T18:16:17Z")

</div>

OK, I gave up and used cmake-gui to build glfw and it did and got everything built including the programs in tests and examples directories. Not an enlightening experience since I still do not know what I need to do to get my simple glfw vulkan program running. Anyway triangle-vulkan is running fine so apparently nothing wrong with my visual studio or glfw copy. And to do justice this 2230 line C program has a bit of animation a little more than the 920 line C++ program that has a fixed static triangle.

---

<div class="post-metadata">

**Author:** ![HishamMSueyllam](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/hishammsueyllam/32/324_2.png) [@HishamMSueyllam](https://discourse.glfw.org/u/HishamMSueyllam)\
**Post date:** [April 10, 2020, 6:34pm UTC](https://discourse.glfw.org/t/glfw-on-msys2-on-windows-10-and-vulkan/1529/11 "2020-04-10T18:34:59Z")

</div>

There were no control over cmake and it generated 32-bit versions of everything as I checked with sigcheck. Do I need to use the command line cmake to get 64-bit versions? or there is a way and still uses gui cmake.

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [April 10, 2020, 6:54pm UTC](https://discourse.glfw.org/t/glfw-on-msys2-on-windows-10-and-vulkan/1529/12 "2020-04-10T18:54:39Z")

</div>

With cmake-gui you can click on `Configure` and then select the generator (Visual Studio NN YYYY) and platform (Win32 or x64).

---

<div class="post-metadata">

**Author:** ![HishamMSueyllam](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/hishammsueyllam/32/324_2.png) [@HishamMSueyllam](https://discourse.glfw.org/u/HishamMSueyllam)\
**Post date:** [April 10, 2020, 10:31pm UTC](https://discourse.glfw.org/t/glfw-on-msys2-on-windows-10-and-vulkan/1529/13 "2020-04-10T22:31:57Z")

</div>

Yes thanks it worked but there is a catch it overwrote the 32-bit versions of everything including the libs. I was hoping to keep both but if I ever needed the 32-bit version I guess I’ll have to make a fresh copy of the master glfw dir

---

<div class="post-metadata">

**Author:** ![HishamMSueyllam](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/hishammsueyllam/32/324_2.png) [@HishamMSueyllam](https://discourse.glfw.org/u/HishamMSueyllam)\
**Post date:** [April 11, 2020, 1:29am UTC](https://discourse.glfw.org/t/glfw-on-msys2-on-windows-10-and-vulkan/1529/14 "2020-04-11T01:29:45Z")

</div>

And also to make sure that my mingw64 under msys2 is also fine along with its own copy of glfw I tried to build the test program triangle-vulkan.c. It took me a while to figure out how, but by looking at the glad page at github I found out that I needed to link with -ldl on mingw to build glad.c which I obtained from the red book of opengl version 9 code, and using the command after installing libdl.a:

gcc -o triangle-vulkan triangle-vulkan.c glad.c glad\_vulkan.c -lglfw3 -ldl -lvulkan -lwinmm -lgdi32 -Wl,–subsystem,windows

and the animated triangle showed up.  
Conclusion: something is definitely fuzzy about how glfwCreateWindowSurface behaves and causes it to return VK\_ERR while all data passed to it are fine as I checked by printing to cerr in the hell triangle.cpp tutorial program.

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [April 11, 2020, 10:07am UTC](https://discourse.glfw.org/t/glfw-on-msys2-on-windows-10-and-vulkan/1529/15 "2020-04-11T10:07:31Z")

</div>

Since triangle-vulkan.c works but triangle 15\_hello\_triangle.cpp does not the first conclusion is that there might be a problem in the triangle 15\_hello\_triangle.cpp code.

Whilst there is potentially an issue with `glfwCreateWindowSurface` this is less likely as there are a large number of users of the code who have not experienced issues.

Is the full tutorial code available on github or somewhere to download? I may get time to investigate the issue, though you should also try contacting the tutorial author via their website.

---

<div class="post-metadata">

**Author:** ![HishamMSueyllam](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/hishammsueyllam/32/324_2.png) [@HishamMSueyllam](https://discourse.glfw.org/u/HishamMSueyllam)\
**Post date:** [April 11, 2020, 11:19am UTC](https://discourse.glfw.org/t/glfw-on-msys2-on-windows-10-and-vulkan/1529/16 "2020-04-11T11:19:35Z")

</div>

If you go to this page of the tutorial you’ll find at the end of the explanatory text the c++ code and fragment and vertex shader hypertext that upon clicking on will open a page with the code that you can copy-paste into your machine:

[https://vulkan-tutorial.com/en/Drawing\_a\_triangle/Drawing/Rendering\_and\_presentation](https://vulkan-tutorial.com/en/Drawing_a_triangle/Drawing/Rendering_and_presentation)

Hope you can patch this problem, I really found it much easier to grasp c++ rather than C in dealing with the colossal job of setting up vulkan…

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [April 11, 2020, 11:37am UTC](https://discourse.glfw.org/t/glfw-on-msys2-on-windows-10-and-vulkan/1529/17 "2020-04-11T11:37:23Z")

</div>

_Hope you can patch this problem_

Just to clear up expectations - I may get a few minutes to help you investigate the issue but the ultimate responsibility for this code lies with it’s author, once again I suggest you contact them, there is a comment section at the bottom of the page you linked to.

---

<div class="post-metadata">

**Author:** ![HishamMSueyllam](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/hishammsueyllam/32/324_2.png) [@HishamMSueyllam](https://discourse.glfw.org/u/HishamMSueyllam)\
**Post date:** [April 11, 2020, 12:29pm UTC](https://discourse.glfw.org/t/glfw-on-msys2-on-windows-10-and-vulkan/1529/18 "2020-04-11T12:29:44Z")

</div>

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](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. First this program gives a segmentation fault, and upon replacing glfwCreateWindowSurface by the same exsact code that I used in the working version of hello triangle in mingw64, the program runs but it seems to have another issue since I get a blank window with nothing but at least the memory segmentation fault is gone.  
It could be nasty problems with pointers when switching between C and C++

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [April 11, 2020, 12:35pm UTC](https://discourse.glfw.org/t/glfw-on-msys2-on-windows-10-and-vulkan/1529/19 "2020-04-11T12:35:35Z")

</div>

I was able to build the program and run it, but in my case it manages to create a surface without problems but I get an read access violation in the call to vkCreateGraphicsPipelines on line 532.

Since I didn’t create this code, it’s tricky to debug what’s going on.

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [April 11, 2020, 12:36pm UTC](https://discourse.glfw.org/t/glfw-on-msys2-on-windows-10-and-vulkan/1529/20 "2020-04-11T12:36:52Z")

</div>

Note that there is no _nasty problems with pointers when switching between C and C++_ .

[Next page](https://discourse.glfw.org/t/glfw-on-msys2-on-windows-10-and-vulkan/1529.md?page=2)
