sfml sdl2 windows vscode 调试和coderunner插件运行

链接库写在编译链接命令里,如果没有使用到不会加入到生成的可执行文件里。所以tasks.json可以这样写,

复制代码
{
	"version": "2.0.0",
	"tasks": 
	[
		{
			"type": "cppbuild",
			"label": "C/C++: g++.exe 生成活动文件",
			"command": "D:\\mingw64_1310\\bin\\g++.exe",
			"args": 
			[
				"-fdiagnostics-color=always",
				"-g",
				"-std=c++17",
				"*.cpp",
				
				"-lmingw32",
				"-lSDL2main",
				"-lSDL2",
				"-lSDL2_image",
				"-lSDL2_ttf",
				"-lSDL2_mixer",

				"-lsfml-audio",
				"-lsfml-graphics",
				"-lsfml-window",
				"-lsfml-system"
			],
			"options": 
			{
				"cwd": "${fileDirname}"
			},
			"problemMatcher": 
			[
				"$gcc"
			],
			"group": 
			{
				"kind": "build",
				"isDefault": true
			},
			"detail": "编译器: D:\\mingw64_1310\\bin\\g++.exe",
			"presentation": 
			{            //
                "reveal": "silent",
                "revealProblems": "onProblem",
                "close": true
            }
		}
	]
}

coderunner插件可以如下这样写,

复制代码
{
   
    "code-runner.executorMap": 
    {
        "cpp": "cd $dir && g++ *.cpp -std=c++17 -Wall -fexec-charset=gbk -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer -lsfml-audio -lsfml-graphics -lsfml-window -lsfml-system && ./a",
    }
}

launch.json是如下,

复制代码
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C/C++: g++.exe 生成和调试活动文件",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\a.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\mingw64_1310\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "将反汇编风格设置为 Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe 生成活动文件"
        }
    ]
}

以上都是windows平台。以上2个库都没有包括网络库的链接。

下面的系统环境变量 配置好后有可能需要重启电脑。 操作系统Path设置可以用分号 ; 也把sfml和sdl2的库和包含路径都写上,

新建的CPLUS_INCLUDE_PATH,LIBRARY_PATH,

PATH里面放bin目录的dll文件路径,

相关推荐
天外飞雨道沧桑22 分钟前
前端开发 Cursor MCP 提效工具配置
前端·vscode·ai编程·开发工具·cursor
悟能不能悟1 小时前
怎么在idea合并2个个branch
java·ide·intellij-idea
倦王1 小时前
vscode 中如何去选择不同的远程环境去debug
ide·vscode·编辑器
至天5 小时前
Windows 10/11 终端(Windows Terminal)右键菜单缺失恢复方法
windows·终端·windows 11·windows 10·terminal·右键菜单·windowsterminal
焚 城5 小时前
Visual Studio 2026来临
ide·visual studio
光年像素5 小时前
WMIC(Windows Management Instrumentation Command-line)命令大全
windows
m0_528489256 小时前
Pycharm修改系统缓存路径(包含config, system, plugins, logs, remote sources等)
ide·python·pycharm·c盘
Franklin6 小时前
AI Coding 基础实践03 - Trae AI在Pycharm中的使用02 - 读取不了项目的文件问题解决
ide·python·pycharm
帮帮志6 小时前
PyCharm 开发工具 不同的模式
ide·python·pycharm
q***575010 小时前
Redis服务安装自启动(Windows版)
数据库·windows·redis