如何解决错误LNK2019:未解决的外部符号_glfwinit

发布于 2025-02-14 00:35:10 字数 2344 浏览 0 评论 0原文

我有来自Vulkan教程的基本代码。我不是使用Visual Studio,而是选择仅从命令行中编译。 cl lib/*。lib main.cpp/i包括。我假设这些符号将在似乎正确编译的。

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

这是编译器/链接器的完整输出

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失而复得 2025-02-21 00:35:10

首先,我必须安装Windows 10 SDK
然后,我不得不在通往VS2022的路径中更改我的vcvarsall
然后我必须运行vcvarsall x64
然后,我必须删除glfw3.lib支持glfw3_mt.lib
然后,我必须将vulkan-1.lib添加到我的lib/目录
最后,它编译并展示了一个窗户

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文