【问题标题】:trouble linking with glfw using premake and vs2019使用 premake 和 vs2019 与 glfw 链接时出现问题
【发布时间】: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 个错误

标签: c++ glfw premake


【解决方案1】:

感谢 'Botje' 的评论,我意识到 premake 脚本中有一堆丢失的文件。 (我从另一个项目得到这个文件,并错误地认为它是正确的)

我在查看 glfw 项目源目录中的 CMakeLists.txt 时发现了丢失的文件。

这是 glfw 项目的新 lua premake 脚本:

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/internal.h",
    "src/platform.h",
    "src/mappings.h",
    "src/context.c",
    "src/init.c",
    "src/input.c",
    "src/monitor.c",
    "src/platform.c",
    "src/vulkan.c",
    "src/window.c",
    "src/egl_context.c",
    "src/osmesa_context.c",
    "src/null_platform.h",
    "src/null_joystick.h",
    "src/null_init.c",

    "src/null_monitor.c",
    "src/null_window.c",
    "src/null_joystick.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_module.c",
        "src/win32_joystick.c",
        "src/win32_monitor.c",
        "src/win32_time.h",
        "src/win32_time.c",
        "src/win32_thread.h",
        "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"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-26
    相关资源
    最近更新 更多