Setting up Vulkan on MacOS

Setting up Vulkan development environment on MacOS using Xcode.

  1. Download the latest SDK from the LunarG website

  2. Extract the downloaded file and install SDK. Remember your installed path.

  3. Install GLFW

    1
    brew install glfw
  4. Install GLM

    1
    brew install glm
  5. Configure Xcode

Start a new project and choose Command Line Tool. For the language, select C++. Add the following code example to main.cpp.

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>

#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/vec4.hpp>
#include <glm/mat4x4.hpp>

#include <iostream>

int main() {
glfwInit();

glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
GLFWwindow* window = glfwCreateWindow(800, 600, "Vulkan window", nullptr, nullptr);

uint32_t extensionCount = 0;
vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr);

std::cout << extensionCount << " extensions supported\n";

glm::mat4 matrix;
glm::vec4 vec;
auto test = matrix * vec;

while(!glfwWindowShouldClose(window)) {
glfwPollEvents();
}

glfwDestroyWindow(window);

glfwTerminate();

return 0;
}

You will see a lot of error messages at the beginning. We need to configure the project. Select the project and go to Build Settings. Find Header Search Paths and Library Search Paths.

  1. For Header Search Paths, add links: /usr/local/include [your_vk_location]/macOS/include
  2. For Library Search Paths, add links: /usr/local/lib [your_vk_location]/macOS/lib

Then go to Build Phases tab and add glfw3 and vulkan dynamic libraries.

After adding these libraries, in the same tab, open Copy Files, change Destination to “Frameworks”, clear the subpath and uncheck “Copy only when installing”. Click “+” and add all the three libraries here.

  1. Run demo

Run the project and you should see a Vulkan window displaying on your screen.

Reference

Author

Joe Chu

Posted on

2025-03-11

Updated on

2025-03-11

Licensed under

Comments