Terminal g++ Compiler

Hi Can I have a question here??
I am a college student who is majoring in Computer Science. My coding class professor seems to use MacBook and always compile the program using terminal app with g++ something code. I have been using Window for my entire life. I did some research how I can do similar thing in my operating system. It seems there is no advantage using "command prompt" over using Visual Studio to compile the program I wrote! And also people in the Internet say that Mac OS is the best operating system for programmer because of the "terminal" I just don't understand what makes people use command line when they can use either visual studio or XCode to compile.
Visual Studio, XCode and other GUIs are designed to make life easier for you. And they do.

But if you're familiar with working at a terminal, you'll find it more flexible. It's kind of like the difference between driving a car with automatic and manual transmission.

When you start programming, there's so much to learn. Using a GUI removes the need to learn all that console stuff while your trying to learn everything else. But eventually, as a programmer, you'll have to learn something about consoles. But it's fine to ignore them at the start.
Using a terminal to compile gives the programmer a lot more manual flexibility than using an IDE. IDE or terminal command line compiling, there are pros and cons either way.

MSYS2 does terminal style programming on 64-bit Windows, if that is something you would want. Easy to install, packages you want to install are selectable, nearly painless to update. Can create 64- and 32-bit executables. There are even some terminal editor packages available.
https://www.msys2.org/

MSYS2 has packages to compile with MinGW/GCC, Clang and Fortran.
https://solarianprogrammer.com/2019/11/05/install-gcc-windows/

The link is a bit old (2019), but still has some good info about MSYS2 packages.

While for most uses I prefer Visual Studio 2019's IDE, using the MSYS2 terminal setup is not as intimidating as it first appears.

FYI, it is possible to do command-line compiling with VS 2019 if you installed the support.
https://docs.microsoft.com/en-us/visualstudio/ide/reference/command-prompt-powershell?view=vs-2019
https://docs.microsoft.com/en-us/cpp/build/walkthrough-compile-a-c-program-on-the-command-line?view=msvc-160

If you didn't install it originally you can modify it and add it. Just run the VS 2019 installer and select modify.

you can get a unix like command prompt using a program called cygwin. If patched into your windows path, it gives you grep, sed, g++, etc so that cmd will have the vast majority of the unix shell ingrained.
cygwin has gotten very large, though, and the installer is a bit to deal with when cutting it down; install everything is way to much for most people.

g++ filename is a very poor thing to do: g++ by default has relaxed c++ syntax and allows a great many nonstandard c++ language extensions, including variable array sizes, union hack, and more. there are a number of flags you should always use with it, a SMALL sample of the basic ones is from my cygwin batch file:
g++ %1 -O3 -Wall -Wextra -pedantic -std=c++17
(you can use c++ latest or 20 or whatever, I set it up for 17 a long time ago and need to update it. )

The command line has a number of features that really help, but you can use it with visual studio, you don't need a mac for that, and you can use it with the unix extensions as above. There is zero motivation to use a mac and dozens of reasons not to.

I do advise you learn both unix and c++ console at least a little bit. There are a number of powerful features that just a few simple commands unlocks.
examples:
-you can dump a text program (cin, cout no GUI) to a text file when there is a LOT of output or you want to set up input for testing it (you can do this inside visual studio too).
- grep is faster and more flexible than the IDE search and can tap files the IDE search does not see (eg visual studio RC files) or esp searching just a few files with wildcard filenames instead of the built in "whole project, or this file, no other options"
- you can compile the code in g++, to get a 'second opinion' error message or warnings etc to look at, or just sanity check.
- you can quickly delete/copy/backup/interact with code repo/more from console. Many of these are very aggravating to do in a GUI.
- you can do quick little code examples/test syntax or exercise a class with notepad++ and g++ much easier than making a new visual studio project for each little test or toy or whatever.

That said nothing above, if you didn't have it, is a real problem, it just makes things efficient and gives you more tools to use.

You are going to hear that mantra over and over. "unix is better for programmers because XYX" or "mac is better for programmers because XYZ". There is nothing they can do that windows cannot, in terms of software development (in 1985, they were correct, but that was long ago). And the reverse is true too, there isnt anything windows can do that the others cannot. Use what you have, and what you like.
Last edited on
Topic archived. No new replies allowed.