赞
踩
#include<stdio.h>
int main(){
printf("hello VSCode!\n");
return 0;
}
共三个JSON文件需要配置c_cpp_properties.json、tasks.json、launch.json。
此时会自动新增.vscode文件夹,并新建c_cpp_properties.json文件。
"includePath":
[
"${workspaceFolder}/**",
"/Library/Developer/CommandLineTools/usr/include/c++/v1",
"/usr/local/include",
"/Library/Developer/CommandLineTools/usr/lib/clang/10.0.1/include",
"/Library/Developer/CommandLineTools/usr/include"
],
需注意"/Library/Developer/CommandLineTools/usr/lib/clang/10.0.1/include"
中的版本号,可进入finder相应路径确认。
完成后保存(command+s)
点击C/C++:gcc build active file,自动生成tasks.json文件
初始创建的args字段仅包含前四行,我们需要配置第二个和第四个参数,分别为.c文件和生成的可执行.o文件。
另外,添加五六行配置,这两行使vscode运行代码时能够显示运行结果。
"args": [
"-g",
"${workspaceFolder}/hello.c",
"-o",
"${workspaceFolder}/hello.o",
"&&",
"${workspaceFolder}/hello.o"
],
保存。
选择c++(GDB/LLDB)
自动生成launch.json文件并打开
这个字段是要运行的文件路径,写你生成的可执行文件的路径即可,比如我这里是
"program": "${workspaceFolder}/hello.o",
在要编译的文件下,进行编译命令,比如我这里的hello.c激活的情况下,编译(command+shift+B)。
或许会需要选择一个build task to run ,clang或则gcc都OK
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。