【发布时间】:2021-12-02 12:10:56
【问题描述】:
我正在尝试使用 premake 5 构建一个简单的项目。在 win10 上使用 Visual Studio 2019。 Premake 对我来说是新的,但我开始很简单:唯一的依赖项是 glm(仅标头库)、GLAD 和 GLFW。 我将 GLAD 和 GLFW 作为子项目包含在我的 premake 文件中。 项目生成顺利。
glm 已正确包含并可用。
构建时: GLAD 和 GLFW 正确构建到各自的 .lib 文件 但是“核心”应用程序因这些链接器错误而失败:
3>GLFW.lib(init.obj) : error LNK2019: unresolved external symbol _glfwSelectPlatform referenced in function glfwInit
3>GLFW.lib(vulkan.obj) : error LNK2019: unresolved external symbol _glfwPlatformLoadModule referenced in function _glfwInitVulkan
3>GLFW.lib(vulkan.obj) : error LNK2019: unresolved external symbol _glfwPlatformFreeModule referenced in function _glfwInitVulkan
3>GLFW.lib(vulkan.obj) : error LNK2019: unresolved external symbol _glfwPlatformGetModuleSymbol referenced in function _glfwInitVulkan
我在构建 glfw 时一定缺少配置选项
这是负责构建 GLFW 的 premake lua 脚本:
project "GLFW"
kind "StaticLib"
language "C"
targetdir ("bin/" .. outputdir .. "/%{prj.name}")
objdir ("bin-int/" .. outputdir .. "/%{prj.name}")
files
{
"include/GLFW/glfw3.h",
"include/GLFW/glfw3native.h",
"src/glfw_config.h",
"src/context.c",
"src/init.c",
"src/input.c",
"src/monitor.c",
"src/vulkan.c",
"src/window.c"
}
filter "system:linux"
pic "On"
systemversion "latest"
staticruntime "On"
files
{
"src/x11_init.c",
"src/x11_monitor.c",
"src/x11_window.c",
"src/xkb_unicode.c",
"src/posix_time.c",
"src/posix_thread.c",
"src/glx_context.c",
"src/egl_context.c",
"src/osmesa_context.c",
"src/linux_joystick.c"
}
defines
{
"_GLFW_X11"
}
filter "system:windows"
systemversion "latest"
staticruntime "On"
-- buildoptions{
-- "/MT"
-- }
files
{
"src/win32_init.c",
"src/win32_joystick.c",
"src/win32_monitor.c",
"src/win32_time.c",
"src/win32_thread.c",
"src/win32_window.c",
"src/wgl_context.c",
"src/egl_context.c",
"src/osmesa_context.c"
}
defines
{
"_GLFW_WIN32",
"_CRT_SECURE_NO_WARNINGS"
}
filter "configurations:Debug"
runtime "Debug"
symbols "On"
filter "configurations:Release"
runtime "Release"
optimize "On"
【问题讨论】:
-
如果你的目标是使用glfw做一个项目,你最好使用CMake
-
win32_module.c中缺少两个函数。我建议你弄清楚其余的for yourself。 -
感谢您的提示。将 win32_module.c 添加到 glfw 项目文件消除了 3 个错误