提问人:Logos King 提问时间:7/8/2022 更新时间:7/8/2022 访问量:1956
如何修复错误 LNK2019:未解析的外部符号_glfwInit
How do I fix error LNK2019: unresolved external symbol _glfwInit
问:
我有 vulkan 教程中的基本代码。我没有使用Visual Studio,而是选择仅从命令行进行编译。.我有点假设符号将在 .lib 文件似乎可以正确编译,但它没有链接,那么我该怎么办?cl lib/*.lib main.cpp /I include
#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
答:
0赞
Logos King
7/8/2022
#1
首先,我必须安装 Windows 10 SDK
然后我不得不将我的 vcvarsall 路径更改为 VS2022 的路径
然后我必须运行 然后我必须删除 然后我必须将 添加到我的目录中
最后,它编译并显示了一个窗口vcvarsall x64
glfw3.lib
glfw3_mt.lib
vulkan-1.lib
lib/
评论
0赞
Paul Sanders
7/8/2022
你打算如何调试它?
0赞
Logos King
7/9/2022
@PaulSanders 我的策略是不要编写带有错误的代码
0赞
Paul Sanders
7/9/2022
好吧,祝你好运。希望我能做到。
评论