0
votes

I'm trying to use GLFW in Visual Studio for a Vulkan project. After all the include statements the code still shows some errors, all of which are related to GLFW library inclusion. And one error(the last one below) has "stdafx.h" error. I have no idea what stdafx.h is. I'm posting the Code and the errors. Can someone help me with this?

#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" << std::endl;
    glm::mat4 matrix;
    glm::vec4 vec;
    auto test = matrix * vec;
    while (!glfwWindowShouldClose(window)) {
        glfwPollEvents();
    }
    glfwDestroyWindow(window);
    glfwTerminate();
    return 0;
}

Severity Code Description Project File Line Suppression State Error (active) E1696 cannot open source file "GLFW/glfw3.h" VulkanTest c:\Users\H281525\source\repos\VulkanTest\VulkanTest\main.cpp 2

Error (active) E0020 identifier "glfwInit" is undefined VulkanTest c:\Users\H281525\source\repos\VulkanTest\VulkanTest\main.cpp 9

Error (active) E0020 identifier "glfwWindowHint" is undefined VulkanTest c:\Users\H281525\source\repos\VulkanTest\VulkanTest\main.cpp 10

Error (active) E0020 identifier "GLFW_CLIENT_API" is undefined VulkanTest c:\Users\H281525\source\repos\VulkanTest\VulkanTest\main.cpp 10

Error (active) E0020 identifier "GLFW_NO_API" is undefined VulkanTest c:\Users\H281525\source\repos\VulkanTest\VulkanTest\main.cpp 10

Error (active) E0020 identifier "GLFWwindow" is undefined VulkanTest c:\Users\H281525\source\repos\VulkanTest\VulkanTest\main.cpp 11

Error (active) E0020 identifier "window" is undefined VulkanTest c:\Users\H281525\source\repos\VulkanTest\VulkanTest\main.cpp 11

Error (active) E0020 identifier "glfwCreateWindow" is undefined VulkanTest c:\Users\H281525\source\repos\VulkanTest\VulkanTest\main.cpp 11

Error (active) E0020 identifier "vkEnumerateInstanceExtensionProperties" is undefined VulkanTest c:\Users\H281525\source\repos\VulkanTest\VulkanTest\main.cpp 13

Error (active) E0020 identifier "glfwWindowShouldClose" is undefined VulkanTest c:\Users\H281525\source\repos\VulkanTest\VulkanTest\main.cpp 18

Error (active) E0020 identifier "glfwPollEvents" is undefined VulkanTest c:\Users\H281525\source\repos\VulkanTest\VulkanTest\main.cpp 19

Error (active) E0020 identifier "glfwDestroyWindow" is undefined VulkanTest c:\Users\H281525\source\repos\VulkanTest\VulkanTest\main.cpp 21

Error (active) E0020 identifier "glfwTerminate" is undefined VulkanTest c:\Users\H281525\source\repos\VulkanTest\VulkanTest\main.cpp 22

Error C1010 unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source? VulkanTest c:\users\h281525\source\repos\vulkantest\vulkantest\main.cpp 25

1
Welcome to Stack Overflow! To give you a great answer, it might help us if you have a glance at How to Ask if you haven't already. It might be also useful if you could provide a minimal reproducible example. - Mat

1 Answers

0
votes

E1696 cannot open source file "GLFW/glfw3.h"

Quite self-explanatory. The compiler cannot find the GLFW/glfw3.h. Just add the directory containing the GLFW folder into your Additional Include Directories.

E0020 identifier "glfwWhatever" is undefined

Direct result of the above, because the #include failed.

Error C1010 unexpected end of file while looking for precompiled header.

If you do not want to use Precompiled Header, then just disable it in Project Properties. Otherwise it has to be provided (by default stdafx.h)