LinuxでのvscodeのC ++プロジェクト構成

準備ができました

インストールvscodeを、あなたが直接(最新バージョン1.3の後に再起動する必要はありません)、インストール後にVisual Studioのコード補完の後で、プラグイン、および再起動のためのC / C ++をインストールし、インストール用のdebパッケージをダウンロードすることができます。

ディレクトリとファイルを生成する

新しいフォルダ[test]を作成し、新しいファイルhelloworld.cppを作成します。ファイルの内容は次のとおりです。

#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
    cout<< "hello world" << endl;
    return 0;
}

vscodeでフォルダーを開きます

c ++ IntelliSenseを構成する

F1を使用して、コマンドオプションを開き、C / C ++と入力し、[C / C ++:構成の編集]を選択して、c_cpp_properties.json構成ファイルを生成します。

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

最も重要なものは、「includePath」参照とライブラリパスであり、参照内容に従って構成されます。

打ち上げ

デバッグインターフェイスで、構成の追加を選択し、c ++(gdb / lgdb)オプションを選択してlaunch.jsonを生成します。名前が示すように、このファイルは主にデバッグ中のロード制御に使用されます。

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/helloworld",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "preLaunchTask": "build",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

注意が必要なパラメーターは「program」です。これはデバッグが必要なターゲットファイルであり、コンパイルされた出力のファイルの場所に設定する必要があります。次に、「preLaunchTask」を追加する必要があります。このアイテムの名前は次のようになります。 Consistentの下に作成されたtasks.jsonのタスク名と同じである必要があります。

tasks.json

コマンドウィンドウにタスクを入力し、タスクを選択します。タスクオプションを構成してtasks.jsonファイルを生成します

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "g++",
            "args":[
                "-g","helloworld.cpp","-o","helloworld"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

launch.jsonの「preLaunchTask」は「label」と同じタスクを呼び出すことに注意してください。

デバッグを開始します

F5キーを押してデバッグを開始します。すべてがそれと同じくらい簡単で、美しい旅を始めます。

カテゴリ:C && C ++の知識Linux

おすすめ

転載: blog.csdn.net/qq_27009517/article/details/112176317