windows上实现vscode编译多个c源文件 - 知乎 (zhihu.com)
1、建立bin/doc/inc/app/src等目录
2、bin目录用来存放生成的exe文件,doc用来存放帮助文档,inc用来存放*.h文件,app用来存放主程序main.c,src用来存放*.c文件
3、修改lauch.json文件
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "gcc.exe - 生成和调试活动文件", "type": "cppdbg", "request": "launch", // "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", "program": "${cwd}\\bin\\${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "externalConsole": false, "MIMode": "gdb", "miDebuggerPath": "C:\\Debug\\msys64\\mingw64\\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++: gcc.exe 生成活动文件" } ] }
4、修改tasks.json
{ "tasks": [ { "type": "cppbuild", "label": "C/C++: gcc.exe 生成活动文件", "command": "C:\\Debug\\msys64\\mingw64\\bin\\gcc.exe", "args": [ "-fdiagnostics-color=always", "-g", // "${file}", "${cwd}\\src\\*.c", "${cwd}\\app\\*.c", "-o", // "${fileDirname}\\${fileBasenameNoExtension}.exe" "${cwd}\\bin\\${fileBasenameNoExtension}.exe", "-lws2_32" ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "调试器生成的任务。" } ], "version": "2.0.0" }
7、在c文件中用相对路径来include源文件,比如
#include "../inc/modbus.h"
标签:bin,文件,gcc,good,vscode,源文件,exe,cwd From: https://www.cnblogs.com/dogingate/p/17880201.html