How to compile C++ code using Visual Studio Code in Ubuntu?

15,955

Solution 1

As far as I know, you do not have any compiler attached to Visual Studio Code. You might be able to attach the terminal to it and run commands there to compile the code.

https://code.visualstudio.com/docs/editor/integrated-terminal

For debugging, try searching for C++ debugger extension in their market place.

https://code.visualstudio.com/docs/editor/debugging

Solution 2

Visual studio Code, Atom, etc. are text editors. You can't compile things on them right off the bat. You'll need to install some plugins/extensions/packages to do that.

https://marketplace.visualstudio.com/items?itemName=brapifra.c-compiler

If you don't want to install plugins on your editor then you can use the terminal to compile and run your code. For this you'll need to install a compiler on your computer.

Cheers!

Solution 3

I use vscode on my Linux system with the CMake Tools and the CMake Tools Helper plugins.

You can select on the bottom status bar in Debug/Release/MinSizedRel/RelWithDebInfo variations without further configuration.

Selecting the debug icon on the left and clicking on the gear icon on the top allows you to create debug build jobs. This requires editing a json file, but the entries are pretty self evident. This allows you to run programs with arguments for debugging purposes in the Debug console, with or without running a debugger.

Share:
15,955

Related videos on Youtube

Amir
Author by

Amir

Doing research on building models that mimic human behavior. Hope to take steps towards building real AI models in the future GitHub

Updated on June 04, 2022

Comments

  • Amir
    Amir almost 2 years

    I've been looking at some online resources on how can I compile a C++ project using Visual Studio Code. I'm very new to Visual Studio Code but I could not find a tutorial that clearly explains how I can compile a large C++ project that requires CMake with some arguments to enable debugging in a Unix-based operating systems like Ubuntu. The closest thing I found was this which seems pretty concise, which might be enough for more expert users. So I wonder, can someone give some step-by-step instructions on how I should set up VSCode and compile C++ code and enable debugging with GDB?

    FYI, I have installed the C++ and CMake extensions.

    • Pierre
      Pierre almost 6 years
      You forgot to post the link.
  • Amir
    Amir almost 6 years
    Well I'm looking for instructions on how I can compile a C++ project using those extensions! I didn't ask for general advice, but almost a step-by-step instructions on how I can do that.
  • Amir
    Amir almost 6 years
    Well if I wanted to compile Blender using Terminal I wouldn't ask my question here. I have already installed the C++ extension but I need some more step-by-step guidelines on how I should compile a C++ project in Ubuntu using VS Code :)