-2

I'm in a coding class in which we are coding in C++ through Command Line arguments, but she is using certain things that I'm not able to find through googling but that I've seen elsewhere in posts on this site. My VM is a linux.

What does -Wall do in the context "g++ -Wall -std=c++11 test.cpp -o test"? My instructor also used -o and said it creates an executable file, but I don't see one being made. Is test a command? In layman terms would be best, if possible.

(Somebody used -Wall in a comment on this post for reference Function stoi not declared)

In this vein, what other commands might be helpful when coding in command line? I'm familiar with very basic ones such as cd, ls, pwd, ./a.out, mkdir, cat, and vim (though in vim, I only know how to insert and exit/save).

Thanks for any help; -Wall is my main question but any help on the rest would be super appreciated.

2 Answers2

4

From the g++ man page:

  -Wall
      This enables all the warnings [...]

There's more, feel free to read it.

Ignacio Vazquez-Abrams
  • 740,318
  • 145
  • 1,296
  • 1,325
1

Bless your instructor to teach you compiling on the command line!

The GCC compiler has an extensive documentation here (and might be installed on your computer, available thru info gcc). Read notably the GCC command options chapter (about invoking GCC). You might also try the man pages with man gcc command (but try before man man to understand man(1)...). For gcc, the man page is incomplete (w.r.t. info gcc). And you could also try gcc --help.

I strongly recommend compiling with gcc -Wall -Wextra -g (for C code) or g++ -Wall -Wextra -g for C++ code (also add other useful options such as -std=c++11). The -Wall option asks for almost all warnings, the -Wextra ask for some more of them, and the -g option is asking for debug information (in DWARF format these days). You then can (and should) use the GDB debugger. Read the Debugging with GDB manual.

Later, your excellent instructor probably will teach you about using build automation tools (e.g. GNU make or ninja) which nicely runs commands (notably compilation commands) to automate the build process. A complex program made of several translation units and even using ad hoc C code generators (e.g. bison) can be compiled using make or ninja

Also, you'll probably learn about version control systems such as git.

BTW, I do recommend downloading and studying the source code and building some of the many free software programs (e.g. on http://github.com/ or elsewhere). You'll learn a lot.

BTW, avoid naming your executable test since test is a very standard command (see test(1)) often implemented as a shell builtin.

Basile Starynkevitch
  • 216,767
  • 17
  • 275
  • 509