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

VS Code中使用SFML编译C++代码遇exit code:1错误求助

VSCode中SFML编译C++代码的PowerShell执行失败问题

错误提示

The terminal process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command ../mingw64/bin/gcc.exe -v -g src/*.cpp -o bin/main.exe -DDEBUG -I../lib/SFML/include -L../lib/SFML/lib -lmingw32 -lstdc++ -lsfml-graphics -lsfml-window -lsfml-system" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it.

配置文件

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "GCC build and debug",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/bin/main.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            //Pay attention to change to your own MinGW directory
            "miDebuggerPath": "../mingw64//bin/gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "Build"
        }
    ]
}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "GCC_Debug",
            "command": "../mingw64/bin/gcc.exe",
            "args": [
                "-v",
                "-g",
                "src/*.cpp",
                "-o",
                "bin/main.exe",
                "-DDEBUG",
                "-I../lib/SFML/include",
                "-L../lib/SFML/lib",
                "-lmingw32",
                "-lstdc++",
                "-lsfml-graphics",
                "-lsfml-window",
                "-lsfml-system"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": ["$gcc"],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "label": "Copy_Assets",
            "command": "copy",
            "args": ["\"src/gfx/*.*\" \"bin/gfx/\""],
            "type": "shell"
        },
        {
            "label": "Build",
            "dependsOn": ["GCC_Debug", "Copy_Assets"]
        }
    ]
}

环境信息

  • SFML:版本2.6.0(GCC 13.1.0 MinGW (SEH) - 64-bit),安装路径为./lib/SFML
  • MinGW:版本MinGW-W64 GCC-8.1.0/x86_64-posix-seh,安装路径为./mingw64

执行情况对比

  • Git Bash中执行成功:
../mingw64/bin/gcc.exe -g src/*.cpp -o bin/main.exe -DDEBUG -I../lib/SFML/include -L../lib/SFML/lib -lmingw32 -lstdc++ -lsfml-graphics -lsfml-window -lsfml-system
$ echo $?
0
  • PowerShell中执行失败:
PS D:\Users\Mathieu\Documents\Programmation\git\cpp\raytracing> ../mingw64/bin/gcc.exe -g src/*.cpp -o bin/main.exe -DDEBUG -I../lib/SFML/include -L../lib/SFML/lib -lmingw32 -lstdc++ -lsfml-graphics -lsfml-window -lsfml-system
PS D:\Users\Mathieu\Documents\Programmation\git\cpp\raytracing> $LastExitCode
1

项目结构(以./raytracing为工作目录)

./lib/SFML
./mingw64
./raytracing/.vscode/c_cpp_properties.json
./raytracing/.vscode/launch.json
./raytracing/.vscode/settings.json
./raytracing/.vscode/tasks.json
./raytracing/bin/main.exe
./raytracing/src/main.cpp

寻求帮助解决该编译错误问题。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 02:27:01