-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.

  • 1
    Why not Google the manual page? Would have been quicker. Google man g++ – Ed Heal Sep 04 '17 at 19:25
  • 1
    Or use the man page, period. – Rob Sep 04 '17 at 19:25
  • Type `man gcc` on the command line. – DYZ Sep 04 '17 at 19:26
  • Thanks for the downvotes! I literally didn't know the man page was a thing, and googling -Wall yielded no results, but they were probably justified. Sounds right. Legitimate thanks to Basile Starynkevitch! – ULTIMATEDEMISE2 Sep 04 '17 at 19:46
  • It's harsh to down-vote this :/ Also, it's difficult to Google a term that matches a common word like "wall". It only takes ten seconds to answer the question, if you know the answer. – Kevin Boone Sep 05 '17 at 07:28
  • @ULTIMATEDEMISE2: If my answer fits, please accept it and/or upvote it. – Basile Starynkevitch Sep 05 '17 at 07:46
  • I don't have the rep to or I would. – ULTIMATEDEMISE2 Sep 06 '17 at 20:09
  • @ULTIMATEDEMISE2 The tricky thing about googling compiler flags that start with dashes is that in google search, starting a term with a dash means to **exclude** things that match that term from the results. So to actually get the dash, you need to wrap it with quotes like `"-Wall"`. – starball Dec 28 '22 at 07:50

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
  • 776,304
  • 153
  • 1,341
  • 1,358
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
  • 223,805
  • 18
  • 296
  • 547