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

VSCode静态链接GLFW时出现undefined reference to `__mingw_vsscanf'错误

OpenGL + GLFW + glad 编译错误排查与解决

遇到的问题

  • 初始使用64位GLFW(glfw-3.4.bin.WIN64)搭配32位MinGW g++ 6.3.0编译器,编译时出现undefined reference to 'glfwInit()'错误
  • 更换为32位GLFW后,出现undefined reference to '__mingw_vsscanf'错误

项目文件结构

-root:
    -.vscode:
        tasks.json
    -build:(empty)
    -include:
        -glad:
            glad.h
        -GLFW:
            glfw3.h
            glfw3native.h
        -KHR:
            khrplatform.h
    -src:
        glad.c
        main.cpp
    .gitignore
    libglfw3.a

tasks.json 配置

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "C:/MinGW/bin/g++.exe",
            "args": [
                "-std=c++17",
                "-I${workspaceFolder}/include",
                "${workspaceFolder}/src/glad.c",
                "${workspaceFolder}/src/main.cpp",
                "${workspaceFolder}/libglfw3.a",
                "-o",
                "${workspaceFolder}/build/output.exe",
                "-lgdi32"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "C:/MinGW/bin/g++.exe"
        }
    ]
}

编译错误信息

c:path/to/Senior-Project/libglfw3.a(context.c.obj):context.c:(.text+0x1b): undefined reference to `__mingw_vsscanf'

已尝试的操作

  • 使用64位GLFW搭配32位MinGW:出现glfwInit()未定义错误
  • 更换为32位GLFW:出现__mingw_vsscanf未定义错误

解决步骤

1. 修复工具链版本兼容性

__mingw_vsscanf是较新版本MinGW才引入的符号,你的g++ 6.3.0版本过旧,与GLFW 3.4预编译32位库不兼容,可选两种方案:

  • 升级MinGW:更换为MinGW-w64 8.1.0及以上的32位版本,确保和GLFW预编译库的编译环境匹配
  • 自行编译GLFW:下载GLFW源码,用你的MinGW 6.3.0通过CMake生成Makefile,编译出适配的libglfw3.a替换现有库

2. 调整编译链接参数

修改tasks.json的args部分,调整库的链接顺序并添加-lmingw32(部分MinGW版本需要显式链接):

"args": [
    "-std=c++17",
    "-I${workspaceFolder}/include",
    "${workspaceFolder}/src/glad.c",
    "${workspaceFolder}/src/main.cpp",
    "-o",
    "${workspaceFolder}/build/output.exe",
    "-lmingw32",
    "${workspaceFolder}/libglfw3.a",
    "-lgdi32"
]

3. 验证文件一致性

  • 确认include/GLFW下的头文件与libglfw3.a版本完全一致
  • 检查glad.c是否正确包含glad.h,且glad生成时选择的OpenGL版本与代码中使用的版本匹配

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.27 17:33:13