This guide is meant to let you compile and run C++ projects made with Vulkan and GLFW on Windows machines without the need to set up Visual Studio or other IDEs first. This all works from the command line, so that you can both compile cross-platform and use the tools you prefer for your development.
This guide was made specifically for a Computer Graphics project at Politecnico di Milano, thus the compilation script provided uses some header files in a directory called headers
. You can simply remove it if you are not working on the same project, as all other steps are supposed to be general for Vulkan and GLFW on any Windows 11 installation.
To install the Vulkan SDK, follow the instructions over here.
The default directory for the Vulkan SDK installation is C:\VulkanSDK
.
Two more components should be installed, as said in the Vulkan Tutorial installation page: GLFW to manage windows and GLM for linear algebra. Download the prebuilt binaries for both and place them in a convenient directory. In the case of this guide, both GLFW and GLM are located in C:\Users\<your user>
.
To install the GNU C Compiler and Make, we'll use Chocolatey, a package manager for Windows.
In order to install Chocolatey, follow the Individual installation instructions found here.
Once Chocolatey is installed, use an elevated PowerShell prompt to install MinGW and Make through the following command:
choco install mingw make
Agree to running all necessary scripts through the installation, otherwise the packages will not be installed.
Now we need to set some environment variables in order for the compiler and libraries to work properly.
To do so, press the Windows key and search for the application "Edit the system environment variables". Usually, simply typing "env" works as well.
On the new open window, select the bottom button "Environment variables…". A new prompt will pop up with two lists: user and system environment variables. We will need to change the user environment variables only.
The Path environment variable should already be setup, as Chocolatey automatically assigns to Path the directory pointing to its executables.
Now, we need to tell GCC where to look for include headers. We can do so through the CPLUS_INCLUDE_PATH
environment variable.
Once again, create a new user environment variable and call it CPLUS_INCLUDE_PATH
. Then, copy and paste the following string to its value:
C:\Users\<your user>\glfw-3.4.bin.WIN64\glfw-3.4.bin.WIN64\include; C:\VulkanSDK\1.3.296.0\Include; C:\Users\<your user>\glm-1.0.1-light\glm
Don't forget to change with your actual user folder name. Also know that if you installed libraries in directories different from the ones cited above, then you are supposed to use those paths instead in this environment variable.
Click "OK" once you're done typing.
Finally, we are going to need to tell GCC where to look for the Vulkan and GLFW libraries. This is done through the LIBRARY_PATH
environment variable.
Create a new user environment variable called LIBRARY_PATH
and paste the following in its value field:
C:\VulkanSDK\1.3.296.0\Lib; C:\Users\<your user>\glfw-3.4.bin.WIN64\glfw-3.4.bin.WIN64\lib-mingw-w64
Again, remember to change the paths accordingly and to use your real user name.
To check whether the installation went smoothly, you can simply close the current PowerShell window, open a new one and type gcc --version
. If the output matches something like the text below:
gcc.exe (Rev3, Built by MSYS2 project) 14.1.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
then your installation is correct. Now check the same thing for the Make package through the command make --version
. You should get a similar text prompt.
If this doesn't happen, check that you followed all steps correctly.
You should simply be able to compile your Windows project through the PowerShell script provided now. If everything works, you should now have a main.exe
file in your project folder which you can run with no problems.
If you are planning to use Make, then create a Makefile
in the project directory and simply type make
. You can look at how to create Makefiles online.
If the script cannot run and you get an execution policy error, then your PC is not set up to run scripts that have no digital signatures, like this one. You can change this by typing the following command:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned
This is the default policy for Windows Server computers, and it lets PowerShell scripts run.
YOU SHOULD NEVER RUN ANYTHING ON YOUR MACHINE WITHOUT INSPECTING IT FIRST. Please visit this link to know more about execution policies.