Skip to content

Instantly share code, notes, and snippets.

@iamwrm
Last active February 6, 2017 01:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamwrm/d731974e370165ac0e0b8036202a0f4a to your computer and use it in GitHub Desktop.
Save iamwrm/d731974e370165ac0e0b8036202a0f4a to your computer and use it in GitHub Desktop.
vscode log of mine

Prerequisite

  • Cmake
  • vscode
  • cpptool extension
brew install cmake

Build with CMake

Create a CMakeLists.txt file in the main project folder with the content of:

cmake_minimum_required(VERSION 3.0)
project(TEST)
set(SOURCE test.cpp)
add_executable(${PROJECT_NAME} ${SOURCE})

Debug directory

mkdir Debug
cd Debug

If we do so, we need to add CMakeLists.txt into Debug dire and change a little bit

cmake_minimum_required(VERSION 3.0)
project(TEST)
set(SOURCE ../test.cpp) 
add_executable(${PROJECT_NAME} ${SOURCE})

IMPORTANT previously, it's test.cpp, now it's ../test.cpp

Execute command:

cmake -DCMAKE_BUILD_TYPE=Debug
make

Debug the program (with LLDB)

Start VSCode's debug mode using View, Debug or Shift(⇧)+Command(⌘)+D. You'll see that left pane changes to DEBUG and states C++ Launch.

Activate the settings (wheel) icon to open the launch.json file and ensure that the sections referencing "program" is specifying the main executable file TEST.

"program": "${workspaceRoot}/Debug/TEST",

Save the launch.json file.

Monaco Menlo Consolas "Droid Sans Mono" "Inconsolata" "Courier New" monospace (fallback)

gist plugin no problem

after all vscode is not powerful enough

I should treat it as a light editor

emacs(spacemacs)is something worth learning

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "g++",
"isShellCommand": true,
"args": [
"${fileBasename}",
"-o",
"${fileBasenameNoExtension}"
],
"showOutput": "always"
}

Variable substitution

When authoring tasks configurations, it is often useful to have a set of predefined common variables. VS Code supports variable substitution inside strings in the tasks.json file and has the following predefined variables:

${workspaceRoot} the path of the folder opened in VS Code
${workspaceRootFolderName} the name of the folder opened in VS Code without any slashes (/)
${file} the current opened file
${relativeFile} the current opened file relative to workspaceRoot
${fileBasename} the current opened file's basename
${fileBasenameNoExtension} the current opened file's basename without the extension
${fileDirname} the current opened file's dirname
${fileExtname} the current opened file's extension
${cwd} the task runner's current working directory on startup

You can also reference environment variables through ${env.Name} (e.g. ${env.PATH}). Be sure to match the environment variable name's casing, for example env.Path on Windows.

Below is an example of a configuration that passes the current opened file to the TypeScript compiler.

{
    "command": "tsc",
    "args": ["${file}"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment