Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 518
Amir Avatar asked Jul 23 '18 16:07

Amir


3 Answers

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

like image 169
liviu ungureanu Avatar answered Oct 01 '22 15:10

liviu ungureanu


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!

like image 21
involtus Avatar answered Oct 01 '22 16:10

involtus


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.

like image 29
Michael Surette Avatar answered Oct 01 '22 14:10

Michael Surette