2

I'm using the Code Runner extension in vs code,

I want to change the output directory of compiled-cpp (.exe) files but I don't know what variable-name I will type in

  • my "settings.json" file :
"code-runner.executorMap": {
    
        "javascript": "node",
        "java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
        "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", // <- this

Is anyone know where the variable-name documentation for this case ? anyway sorry for my bad english

I've tried to implement from https://code.visualstudio.com/docs/editor/variables-reference like this :

"cpp": "cd $dir && g++ $file -o $workspaceFolder\\C++\\bin\\$fileNameWithoutExt && $workspaceFolder\\C++\\bin\\$fileNameWithoutExt",

and I got : Unexpected token '\C++\bin\stringComparison' in expression or statement

3 Answers 3

4

formulahendry/vscode-code-runner: Code Runner for Visual Studio Code (github.com)

Supported customized parameters

  • $workspaceRoot: The path of the folder opened in VS Code
  • $dir: The directory of the code file being run
  • $dirWithoutTrailingSlash: The directory of the code file being run without a trailing slash
  • $fullFileName: The full name of the code file being run
  • $fileName: The base name of the code file being run, that is the file without the directory
  • $fileNameWithoutExt: The base name of the code file being run without its extension
  • $driveLetter: The drive letter of the code file being run (Windows only)
  • $pythonPath: The path of Python interpreter (set by Python: Select Interpreter command)

Please take care of the back slash and the space in file path of the executor

  • Back slash: please use \\
  • If there ares spaces in file path, please use \" to surround your file path
Sign up to request clarification or add additional context in comments.

Comments

1

Open Visual Studio Code -> Setting -> Upper right corner -> Press open setting.json and then edit the code runner executorMap "cpp" with this command.

"code-runner.executorMap": {
        "cpp": "cd $dir && g++ -std=c++17 \"$fileName\" -o \"$fileNameWithoutExt.o\" && $dir\"$fileNameWithoutExt.o\"",
}

Comments

0

Let's say your path is - /home/your-username/your-project/folder/file.cpp Now you make a "build" directory in which you can output your compiled files with path - /home/your-username/your-project/folder/build

So you change your setting.json to this

OLD: "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",

NEW: "cpp": "cd $dir && g++ $fileName -o $dir/build/$fileNameWithoutExt && $dir/build/$fileNameWithoutExt",

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.