C / C++

About

This module contains 2 languages:

  • C is a general-purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, while a static type system prevents unintended operations.

  • C++ is a general-purpose programming language created by Bjarne Stroustrup as an extension of the C programming language, or C with Classes.

Installation

Change enable from False to True in the c_cpp section (cf module installation).

vscode-anywhere:
    c_cpp:
        enabled: True

You can also take a look at the VSCode-Anywhere c_cpp module configuration.

Requirements

After installing this module, you must configure it because it doesn't work out of the box.

Indeed to work the module ms-vscode.cpptools needs to have a valid.vscode/c_cpp_properties.json file.

You can configure it by running the command C/C++: Edit Configurations (UI) or C/C++: Edit Configurations (JSON) from the Command Palette (Ctrl+Shift+P).

For more details read the official configuration and how to configure it with:

You could also read:

Windows examples

You can also create a task file .vscode/tasks.json to compile your program:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "clang build active file",
            "command": "C:\\VSCode-Anywhere\\apps\\scoop\\apps\\msys2\\current\\mingw64\\bin\\clang.exe",
            "args": [
                "-std=c11",
                "-Wall",
                "-Wextra",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            }
        },
        {
            "type": "shell",
            "label": "clang++ build active file",
            "command": "C:\\VSCode-Anywhere\\apps\\scoop\\apps\\msys2\\current\\mingw64\\bin\\clang++.exe",
            "args": [
                "-std=c++17",
                "-Wall",
                "-Wextra",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            }
        }
    ]
}

You can also create the .vscode/launch.json file to run the debugger:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) clang",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\VSCode-Anywhere\\apps\\scoop\\apps\\msys2\\current\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Activer l'impression en mode Pretty pour gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "clang build active file"
        },
        {
            "name": "(gdb) clang++",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\VSCode-Anywhere\\apps\\scoop\\apps\\msys2\\current\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Activer l'impression en mode Pretty pour gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "clang++ build active file"
        }
    ]
}

There are examples and assuming you have installed in the default directory C:\VSCode-Anywhere.

VSCode

VSCode extensions

ms-vscode.cpptools

This extension adds language support for C/C++ to Visual Studio Code, including features such as IntelliSense and debugging.

jbenden.c-cpp-flylint

This extension is an advanced, modern, static analysis extension for C/C++ that supports a number of back-end analyzer programs.

matepek.vscode-catch2-test-adapter

This extension allows you to run your Catch2, Google Test, and doctest (experimental) tests for Visual Studio Code.

VSCode-Anywhere does not install Catch2, Google Test or doctest. You have to install them by yourself.

ms-vscode.cmake-tools

CMake Tools provides the native developer a full-featured, convenient, and powerful workflow for CMake-based projects in Visual Studio Code.

For more information take a look at the official documentation.

VSCode settings

Global settings

{
    "dash.languageIdToDocsetMap.c": [
        "c"
    ],
    "C_Cpp.default.cStandard": "c11",
    "C_Cpp.default.cppStandard": "c++17",
    "c-cpp-flylint.flexelint.enable": true,
    "c-cpp-flylint.cppcheck.enable": true,
    "c-cpp-flylint.clang.enable": false
}

If llvm is enabled:

{
    "c-cpp-flylint.flexelint.enable": false,
    "c-cpp-flylint.cppcheck.enable": false,
    "c-cpp-flylint.clang.enable": true
}

Windows settings

Global settings for Windows:

{
    "cmake.cmakePath": "C:\\VSCode-Anywhere\\apps\\scoop\\apps\\msys2\\current\\mingw64\\bin\\cmake.exe"
}

If llvm is disabled:

{
    "C_Cpp.default.compilerPath": "C:\\VSCode-Anywhere\\apps\\scoop\\apps\\msys2\\current\\mingw64\\bin\\gcc.exe",
    "c-cpp-flylint.clang.executable": "C:\\VSCode-Anywhere\\apps\\scoop\\apps\\msys2\\current\\mingw64\\bin\\g++.exe",
    "code-runner.executorMap.c": "C:\\VSCode-Anywhere\\apps\\scoop\\apps\\msys2\\current\\mingw64\\bin\\gcc.exe $fileName -o $fileNameWithoutExt.exe && $fileNameWithoutExt.exe",
    "code-runner.executorMap.cpp": "C:\\VSCode-Anywhere\\apps\\scoop\\apps\\msys2\\current\\mingw64\\bin\\g++.exe $fileName -o $fileNameWithoutExt.exe && $fileNameWithoutExt.exe",
    "c-cpp-flylint.cppcheck.executable": "C:\\VSCode-Anywhere\\apps\\scoop\\apps\\msys2\\current\\mingw64\\bin\\cppcheck.exe"
}

If llvm is enabled:

{
    "C_Cpp.default.compilerPath": "C:\\VSCode-Anywhere\\apps\\scoop\\apps\\msys2\\current\\mingw64\\bin\\clang.exe",
    "c-cpp-flylint.clang.executable": "C:\\VSCode-Anywhere\\apps\\scoop\\apps\\msys2\\current\\mingw64\\bin\\clang.exe",
    "code-runner.executorMap.c": "C:\\VSCode-Anywhere\\apps\\scoop\\apps\\msys2\\current\\mingw64\\bin\\clang.exe $fileName -o $fileNameWithoutExt.exe && $fileNameWithoutExt.exe",
    "code-runner.executorMap.cpp": "C:\\VSCode-Anywhere\\apps\\scoop\\apps\\msys2\\current\\mingw64\\bin\\clang++.exe $fileName -o $fileNameWithoutExt.exe && $fileNameWithoutExt.exe"
}

Assuming you have installed in the default directory C:\VSCode-Anywhere.

Linux settings

Global settings for Linux:

{
    "cmake.cmakePath": "/home/linuxbrew/.linuxbrew/bin/cmake"
}

If llvm is disabled:

{
    "code-runner.executorMap.c": "/home/linuxbrew/.linuxbrew/bin/gcc $fileName -o $fileNameWithoutExt && $fileNameWithoutExt",
    "code-runner.executorMap.cpp": "/home/linuxbrew/.linuxbrew/bin/g++ $fileName -o $fileNameWithoutExt && $fileNameWithoutExt",
    "C_Cpp.default.compilerPath": "/home/linuxbrew/.linuxbrew/bin/gcc",
    "c-cpp-flylint.cppcheck.executable": "/home/linuxbrew/.linuxbrew/bin/cppcheck"
}

If llvm is enabled:

{
    "code-runner.executorMap.c": "/home/linuxbrew/.linuxbrew/bin/clang $fileName -o $fileNameWithoutExt && $fileNameWithoutExt",
    "code-runner.executorMap.cpp": "/home/linuxbrew/.linuxbrew/bin/clang++ $fileName -o $fileNameWithoutExt && $fileNameWithoutExt",
    "C_Cpp.default.compilerPath": "/home/linuxbrew/.linuxbrew/bin/clang",
    "c-cpp-flylint.clang.executable": "/home/linuxbrew/.linuxbrew/bin/clang"
}

VSCode keybindings

No keybindings.

Software

Windows software

msys2

if llvm is disable:

if llvm is enabled:

Linux software

brew

If llvm is disable:

If llvm is enabled:

MacOS software

brew

If llvm is disable:

If llvm is enabled:

Documentation

VSCode-Anywhere

Environment

Windows environment

No environment.

Linux environment

Specific settings

llvm

To enable llvm, set llvm to True.

vscode-anywhere:
  c_cpp:
    enabled: False
    llvm: True

Last updated