VSCode配置C工程环境 并 使用sftp同步远程文件

本地配置

task.json是用来配置如何编译该文件的 launch.json是用来配置如何运行/调试该文件的

task.json

  • 首先打开工程所在的文件夹,然后保存成一个工作区
    在这里插入图片描述
    保存后,当前工作目录下会出现.vscode的文件(里面会自动出现一个c_cpp_properties.json,用于一些基本配置,一般来说自动生成的就可以用的),主要存储一些工作区的状态(比如你开了哪些文件之类的,这样能保证这次关闭后下次重新打开布局不变),和一些配置文件(比如task.json,launch.json)


  • 调出工具窗口(有的blogger说是Ctrl+Alt+P,然而我只能通过F1调出来),输入Tasks: Configure Task Runner,选择g++.exe build active file,就会自动生成一个task.json, 我的内含如下内容:
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "g++.exe build active file",
            "command": "D:\\devc\\Dev-Cpp\\MinGW64\\bin\\g++.exe",			//这个是我g++的路径
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "D:\\devc\\Dev-Cpp\\MinGW64\\bin"
            },
            "problemMatcher": [
                "$gcc"
            ]
        }
    ]
}

可以看到这里是编译单个c文件的配置,如果要编译工程,也就是多个c文件,就改写成如下:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "g++.exe build active file",
            "command": "D:\\devc\\Dev-Cpp\\MinGW64\\bin\\g++.exe",
            "args": [
                "-g",
                // "${file}",			
                "test.cpp",				//这两个就是你的工程文件的组成部分,这里以两个为例
                "config.cpp",			//这两个就是你的工程文件的组成部分,这里以两个为例
                "-o",
                "${fileDirname}\\Project.exe" //${fileBasenameNoExtension}  顺便修改下生成的最终的执行文件的名字
            ],
            "options": {
                "cwd": "D:\\devc\\Dev-Cpp\\MinGW64\\bin"
            },
            "problemMatcher": [
                "$gcc"
            ]
        }
    ]
}



vscode的variableName
在这里插入图片描述
详见官网

  • 如果要写成多命令的,如下,用taskName区分不同的task
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "taskName":"build",         //taskName用于区分不同的任务
            "type": "shell",
            "label": "g++.exe build active file",
            "command": "D:\\devc\\Dev-Cpp\\MinGW64\\bin\\g++.exe",
            "args": [
                "-g",
                // "${file}",
                "test.cpp",
                "config.cpp",
                "-o",
                "${fileDirname}\\test.exe" //${fileBasenameNoExtension}
            ],
            "options": {
                "cwd": "D:\\devc\\Dev-Cpp\\MinGW64\\bin"
            },
            "problemMatcher": [
                "$gcc"
            ]
        },
        {
            "taskName":"build-debug",
            "command": "g++",
            // -g 参数用于编译可 debug 的目标文件
            "args": [
                "-g",
                "test.cpp",
                "config.cpp",
                "-o",
                "${fileDirname}\\test-debug.exe"
            ],
            "type": "shell"
        }
    ]
}



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": "g++.exe build and debug active file",			//辅助的名称
            "type": "cppdbg",				//这个千万不能错
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],						// debug的额外参数 调试有特殊需求的时候写在这里(怎么写可以参照task.json
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,		//debug的时候console要不要出现,默认是false
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\devc\\Dev-Cpp\\MinGW64\\bin\\gdb.exe",	//改成自己的g++目录
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "g++.exe build active file"
        }
    ]
}

cpp

之前都不需要配置这个的 ,突然#include报错 ,就得配置下这个了
refer@ https://github.com/Microsoft/vscode-cpptools/issues/1863

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "8.1",
           【windows似乎得自己配置下路径】
            "compilerPath": "D:\\devc\\Dev-Cpp\\MinGW64\\bin\\g++.exe",		
            "cStandard": "c11",
            "cppStandard": "c++17",
            【默认的是msrc-x64  必须得改成这个】
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

SOF上有人说要配置compiler path ,下面有人反驳,事实证明不配置也可以

sftp设置

  • 首先在插件中下载sftp( 第一个 还有个vscode sftp 不用管 )
  • 配置like:
{
    "name": "My Server",
    "host": "xxx.xxx.xxx.xxx",
    "protocol": "sftp",
    "port": 22,
    "username": "你的用户名",
    "password":"你的登陆密码",
    "remotePath": "/YourPath/Your ProjectName",
   
    "uploadOnSave": true
}

存储成sftp.json即可

一般来说如果使用了sftp的话,基本上不用配置本地的task.json之类的了= =

设置(不)同步文件

  • 在sftp.json里面加上ignore的选项即可,详情见上面的link
    • 和.gitignore文件很类似的写法,支持正则和通配
    *.b     # 所有以.b为后缀的文件    *是通配符
    !a.b   # 排除a.b,即a.b不会被忽略   !是非的意思
    /test.txt        # 只忽略根目录下的test.txt文件,而不包括子目录下的test.txt文件,	如/mydir/test.txt就不会被忽略
    /*/test.txt     # 只忽略根目录下某个子目录下的test.txt文件,但/mydir1/mydir2/test.txt不会被忽略
    /**/test.txt   # 忽略根目录下所有test.txt,不管该文件在哪个子目录下,即只有项目中存在		test.txt文件,就会被忽略
    mydir/       # 忽略mydir下的所有文件
    
  • 注意
    • /*/test.txt中的 * 是通配符,因为前面没有其他符号(/不算)
    • /**/test.txt的**,第一个是通配符,理由同上,第二个就是正则匹配,表示0个或者多个

参考资料

https://blog.csdn.net/wzxlovesy/article/details/76708151

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值