您好,欢迎访问一九零五行业门户网

vscode怎么创建C语言项目

1、下载插件c/c++、c++ intellisense;
2、新建一个空文件夹,从vscode打开。 (或file-->open folder-->新建一个空文件夹);
3、按f5(用命令行gcc、g++;或者编写makefile文件,make;),选择c++(gdb/lldb),生成launch.json(用来调试);
4、修改launch.json,将
"program": "enter program name, for example ${workspacefolder}/a.out"
改为
"program": "${workspacefolder}/projectname";"externalconsole": true
表示输出会在弹出的命令行。修改为false的话,会在vscode内部terminal输出。
5、ctrl+shift+b, 选择tasks.json-->模板--->other,生成tasks.json(创建任务);
6、修改 tasks.json,
"command": "echo hello"
改成
"command": "g++ -o projectname projectname.cpp"
这里的projectname和5中的projectname同名
7、对于复杂的项目,"command": "echo hello"改成"command": "make"
8、再创建makefile文件,编辑;
9、编写hello.cpp文件
10、按ctrl+shift+p, 选择 task:run tasks,执行任务
11、按f5,执行
源代码如下所示:
hello.cpp
#include <iostream>using namespace std;int main(){ cout << "hello, world!" << endl; return 0;}
launch.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": "(gdb) launch", "type": "cppdbg", "request": "launch", "program": "${workspacefolder}/hello", "args": [], "stopatentry": false, "cwd": "${workspacefolder}", "environment": [], "externalconsole": true, "mimode": "gdb", "setupcommands": [ { "description": "enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignorefailures": true } ] } ]}
tasks.json
{ // see https://go.microsoft.com/fwlink/?linkid=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "build", "type": "shell", "command": "make" } ]}
makefile或makefile
# objects= main.o kbd.o command.o display.o insert.osearch.o files.o utils.o # edit: $(objects)# cc-o edit $(objects)# main.o: main.c defs.h# cc-c main.c# kbd.o: kbd.c defs.h command.h# cc-c kbd.c# command.o: command.c defs.h command.h# cc-c command.c# display.o: display.c defs.h buffer.h# cc-c display.c# insert.o: insert.c defs.h buffer.h# cc-c insert.c# search.o: search.c defs.h buffer.h# cc-c search.c# files.o: files.c defs.h buffer.h command.h# cc-c files.c# utils.o: utils.c defs.h# cc-c utils.c# clean:# rmedit $(objects)edit: hello.o cc-o edit $(objects)hello.o: hello.c cc-c hello.cclean: rmedit hello.o
相关文章教程推荐:vscode教程
以上就是vscode怎么创建c语言项目的详细内容。
其它类似信息

推荐信息