0

I have the basic code from the vulkan tutorial. I'm not using Visual Studio and opted to just compile from the command line. cl lib/*.lib main.cpp /I include. I sort of assumed that the symbols would be resolved in the .lib files which seem to compile properly, but it doesn't link so what do I do?

#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;
}

This is the full output of the compiler/linker

Microsoft (R) Incremental Linker Version 14.28.29913.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:main.exe
lib/glfw3.lib
lib/glfw3dll.lib
lib/glfw3_mt.lib
main.obj
main.obj : error LNK2019: unresolved external symbol _vkEnumerateInstanceExtensionProperties@12 referenced in function _main
main.obj : error LNK2019: unresolved external symbol _glfwInit referenced in function _main
main.obj : error LNK2019: unresolved external symbol _glfwTerminate referenced in function _main
main.obj : error LNK2019: unresolved external symbol _glfwWindowHint referenced in function _main
main.obj : error LNK2019: unresolved external symbol _glfwCreateWindow referenced in function _main
main.obj : error LNK2019: unresolved external symbol _glfwDestroyWindow referenced in function _main
main.obj : error LNK2019: unresolved external symbol _glfwWindowShouldClose referenced in function _main
main.obj : error LNK2019: unresolved external symbol _glfwPollEvents referenced in function _main
lib\glfw3.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86'
lib\glfw3dll.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86'
lib\glfw3_mt.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86'
main.exe : fatal error LNK1120: 8 unresolved externals
Logos King
  • 121
  • 1
  • 6
  • 4
    According to the message, you look like trying to link libraries for x64 with application code for x86. You should match the kind of the target. – MikeCAT Jul 08 '22 at 13:04
  • 2
    ***lib\glfw3.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86'*** Tells you that you are mixing 64 bit and 32 bit. – drescherjm Jul 08 '22 at 13:06
  • Related if not a duplicate: [https://stackoverflow.com/questions/2548138/how-to-compile-x64-code-with-visual-studio-in-command-line](https://stackoverflow.com/questions/2548138/how-to-compile-x64-code-with-visual-studio-in-command-line) – drescherjm Jul 08 '22 at 13:08
  • 2
    It really would be a lot easier to use Visual Studio. You would have less to assume. – john Jul 08 '22 at 13:51
  • 2
    @john Seconded, and as a bonus you get a first-class debugger thrown in. – Paul Sanders Jul 08 '22 at 14:56

1 Answers1

0

First I had to install the windows 10 SDK Then I had to change my vcvarsall in path to the VS2022 one Then I had to run the vcvarsall x64 Then I had to remove the glfw3.lib in favor of the glfw3_mt.lib Then I had to add the vulkan-1.lib to my lib/ directory And finally it compiled and showed a window

Logos King
  • 121
  • 1
  • 6