Run compiled language (C, C++, Java) in Visual Studio Code

Yes! Compiled language! With the coming of Code Runner extension, we could run many interpreted language directly in VS Code without any configuration. And now, running compiled language (currently C, C++, Java) is supported by Code Runner! Many thanks to the contribution of @manoelcampos.

With support of running compiled language, Code Runner now supports 24 languages: C, C++, Java, JS, PHP, Python, Perl, Ruby, Go, Lua, Groovy, PowerShell, BAT/CMD, BASH/SH, F#, C#, VBScript, TypeScript, CoffeeScript, Scala, Swift, Julia, Crystal, OCaml

The default configuration for C, C++, Java are as below.

"code-runner.executorMap": {
  "java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
  "c": "gcc $fullFileName && ./a.out",
  "cpp": "g++ $fullFileName && ./a.out",
}

As you could see, several placeholders are supported in configuration:

  • $dir: The directory of the code file being run
  • $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

You are free to update or add configuration to support more languages. Come and send a Pull Request for us!

runjava


7 thoughts on “Run compiled language (C, C++, Java) in Visual Studio Code

  1. One example configuration for C/C++ for Windows using MinGW (gcc/g++) is:

    “code-runner.executorMap”: {

    “c”: “gcc -o $fileNameWithoutExt $fullFileName && $fileNameWithoutExt”,
    “cpp”: “g++ -o $fileNameWithoutExt $fullFileName && $fileNameWithoutExt”
    }

    This will both compile and run the file afterwards. If your file’s name is “Program” (Program.cpp), the output will be Program.exe.

    Like

  2. I was wondering if you ever thought of changing the page layout of your site? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having 1 or 2 images. Maybe you could space it out better?|

    Like

Leave a comment