如何解决错误LNK2019:未解决的外部符号_glfwinit
我有来自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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,我必须安装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 theglfw3_mt.lib
Then I had to add the
vulkan-1.lib
to mylib/
directoryAnd finally it compiled and showed a window