Quick run-down: I'm completely new to Ubuntu, but not new to C++: I've coded on a Windows machine before, but I switched to Ubuntu
Now I've installed VS code on Ubuntu as well as the C++ extension but when I even attempt to run a helloworld.cpp
and debug my editor starts throwing up gang signs:
Can anybody help me with this problem?
Best Answer
I had this problem too when I switched to Ubuntu (I'm kind of new too, so I will try to be very clear I understand it's more complicated than Windows). I don't know your experience but, first of all, it is not like any Windows compiler (like devc, borland, etc) where it will output your values on a external console (unless you are debugging). So this are the steps to get a program to work:
You need to install g++
sudo apt-get install g++
and show the compiler where is the include route in a file namedc_cpp_properties.json
in the linux section, like this:First select the folder you are going to work (it's going to be your workspace).
You need to build your program before you put it to work, so you need to create a "task" to do that, so you go to the command pallet (Ctrl+P) and type:
That is going to create a
task.json
and you will have to pick an option (MsBuild, dotNet, Other, etc). So you are going to select "Other" and you will change some values like this:Now press Ctrl+Shift+B
Now, if your program has no errors, is going to output something like this in the integrated terminal
and is going to create a file named
a.out
in your workspace folder, I recommend you download an extension namedCodeRunner
: it adds a play button on the right top corner that you only click and runs the program without debugging. The thing is, it can only output. I mean: if you are expecting the user to input values, you can't (As I said before, I'm also new so I'm not entirely sure you can't).Finally, if you want to debug, you need to configure that one
lauch.json
you uploaded in the images to something like this:https://imgur.com/ioMdDzZ
Pro tip: I would recommend a darker theme!