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

使用C+Raylib编译时出现undefined function错误求助

解决timeEndPeriod未定义引用的编译错误

问题根源

timeEndPeriod是Windows系统API的一部分,属于winmm.lib库。你的编译命令未链接该依赖库,导致链接阶段出现未定义引用错误。

修复步骤

  1. 打开VSCode项目中的.vscode/tasks.json文件
  2. 在编译任务的args数组里,找到现有的链接参数(如-lraylib),在其后添加-lwinmm
  3. 确保tasks.json已正确配置Raylib的头文件与库路径,示例配置如下:
{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: gcc.exe 生成活动文件",
            "command": "C:/msys64/ucrt64/bin/gcc.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "-IC:/your-raylib-path/include",
                "-LC:/your-raylib-path/lib",
                "-lraylib",
                "-lwinmm",
                "-lgdi32",
                "-luser32"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": ["$gcc"],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "编译器: C:/msys64/ucrt64/bin/gcc.exe"
        }
    ]
}
  1. 保存配置后重新执行编译任务

额外注意事项

  • 确保使用的Raylib库是适配MSYS2 UCRT64环境编译的版本,避免因环境不匹配导致的兼容性问题
  • 若Raylib文件存放在项目目录内,将-I和-L的路径改为项目内的相对路径,比如-I${fileDirname}/raylib/include

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 01:07:41