You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows10环境下用Premake5静态链接raylib库出现链接错误如何解决

问题原因

这些未定义引用均来自Raylib依赖的Windows系统底层库,静态链接Raylib时需要手动将这些系统库加入链接列表。

具体修改方案

你需要调整premake5.lua配置,补充Windows平台专属的依赖库,同时修正路径通配符避免搜索错误,修改后的完整配置如下:

// premake5.lua
workspace "foo"
    architecture "x64"
    configurations {"Debug","Release"}
    outputdir = "%{cfg.buildcfg}-%{cfg.architecture}-%{cfg.system}"

project "foo"
    location "./build/"
    kind "ConsoleApp"
    language "C++"
    targetdir "./build/%{cfg.buildcfg}"
    files { "./src/**.cpp",
    "./src/**.c"
    }
    -- 明确指定Raylib头文件搜索路径
    includedirs {"./dependencies/raylib/include"}
    links{"raylib"}
    -- 明确指定Raylib静态库搜索路径
    libdirs{"./dependencies/raylib/lib"}

    -- Windows平台专属依赖库配置
    filter "system:windows"
        links {
            "winmm",
            "gdi32",
            "opengl32",
            "user32",
            "shell32"
        }
        -- 可选配置:静态链接运行时,避免生成的程序依赖额外运行时DLL
        staticruntime "On"
        linkoptions { "-static-libgcc", "-static-libstdc++", "-static" }

    filter "configurations:Debug"
        defines { "DEBUG" }
        symbols "On"

    filter "configurations:Release"
        defines { "NDEBUG" }
        optimize "On"

生效步骤

修改完成后删除build目录下之前生成的Makefile等缓存文件,重新运行premake5 gmake2生成新的编译配置,再执行mingw32-make即可完成正常链接。

内容的提问来源于stack exchange,提问作者UwU OwO

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 13:21:03