AnthonyH
AnthonyH

Reputation: 37

Error running C++ file using Visual Studio in Ubuntu

I am a beginner to Ubuntu and Linux. I'm attempting to run just a simple hello world code and every time I run the C++ code in visual studio, it doesn't actually run, it opens to a new file called settings.json (which is empty). enter image description here

If anyone can help me sole this problem that would be great, thank you.

Upvotes: 1

Views: 978

Answers (3)

I am a beginner to Ubuntu and Linux.

Read about the Unix philosophy.

It is favoring the command line and combination of simple tools

(e.g. in a command pipeline for your unix shell in some terminal emulator). A successful command (e.g. cp(1), used to copy files, or g++(1), a C++ compiler, or man(1) to read documentation, and od(1) or less(1) to inspect a file, or ls(1) to list them) often stays nearly silent when successful; see intro(1). Be aware of syscalls(2) (see also intro(2)). Remember that some parts of your C++ code could be generated (by metaprogramming tools such as ANTLR, swig, or GNU bison or GNU autoconf or GPP, or your own Guile, Python or GAWK or GNU bash script, or some other C++ program, etc...). See also Linux From Scratch. Every executable and process (except /sbin/init) is started by execve(2) with fork(2). See also ps(1), top(1), pstree(1) and proc(5).

Your C++ compiler could be GCC (or else Clang). Be sure to read the documentation on invoking GCC, and about your C++ preprocessor (perhaps GNU cpp). Try g++ --version then g++ --help in some terminal emulator.

If that command works, compile your HelloWorld.cpp with all warnings and debug info, so run in your terminal g++ -Wall -Wextra -g HelloWorld.cpp -o HelloWorld; you later run the obtained executable using ./HelloWorld in the same terminal (read about the $PATH variable in environ(7) and try the printenv(1) command).

Of course, you'll use some IDE or source code editor (e.g. Visual Studio Code, vim or GNU emacs or geany). Be sure to take some time to read its documentation. You'll configure them to run some build automation tool. You surely want to use some version control system, such as git.

And you'll need a debugger such as GDB.

Later, you'll want to use some build automation tool to drive your compilation commands (of several translation units) and the linking command (part of GNU binutils). Consider for your build automation using GNU make or ninja or many others.

Read of course Advanced Linux Programming and some good C++ programming book (and reference website). Be aware that C++ is a very difficult and complex programming language (see its spec n3337).

You could enjoy reading some textbook on operating systems. Study for inspiration the source code of existing open source C++ programs (e.g. on github), such as the fish shell.

Upvotes: 2

anoopknr
anoopknr

Reputation: 3355

It is possible to compile and run C/C++ programs from Visual Studio Code.

To compile and run C/C++ programs from Visual Studio Code (vscode) you need to install C/C++ Compile Run extension from danielpinto8zz6 in Visual Studio Code.

After installing the C/C++ Compile Run extension press F6 to compile and run C/C++ Program.

Hope it helps !

Upvotes: 1

Yunfei Chen
Yunfei Chen

Reputation: 626

You cannot just run the file. The simplest way is to open the command terminal and find where your file is located, the path that it is stored in and type in g++ fileName.cpp, make sure to name it with a cpp extension.

Upvotes: 1

Related Questions