easiest MSWindows G++ installer #c++17

http://strawberryperl.com is an easy installer for Perl and it bundles GCC. I was able to compile in c++17 mode:

g++ -std=c++17 my.cpp

My experiences with cygwin and mingw were both horrible.

  1. cygwin — too bulky and unnecessary, and affected my existing Windows features. I tried sygwin once many years ago and quickly concluded that it was designed for people unlike me. Those people would have only positive experiences about cygwin that I don’t share.
  2. mingw — supposed to be minimalist, but I tried installing it at least 3 (up to 6) times and always painful.

In contrast, I installed strawberryPerl about 3 times and once on a friend’s laptop … always quick and easy. No tweaking required. GCC + gdb works out of the box.

gdb to show c++thread wait`for mutex+condVar shows gdb works out of the box.

Through almost 10 installations of GCC on various windows laptops, I have come to the obvious conclusion.

g++ q[-L] vs [-l] .. [-I] vs [-isystem]

-L and -l (i.e. the big and small "L") both affect the linker only.

See also MSVS linker option -L vs -l #small L

-L (similar to -I) and introduces a new search directory, for *.so or *.a file search.

Q: does the order of -l options matter?
A: yes. Recall the -liberty …

Q: does the order of -L options matter?

-I and -isystem both affect the preprocessor only.

There’s not “-i” option per-se.


q[g++ -g -O] together

https://linux.die.net/man/1/g++ has a section specifically on debugging. It says

GCC allows you to use -g with -O

I think -g adds additional debug info into the binary to help debuggers; -O turns on complier optimization.

By default, our binaries are compiled with “-g3 -O2”. When I debug these binaries, I can see variables but lines are rearranged in source code, causing minor problems. See my blog posts on gdb.

single-stepping 4 stages of g++ compliation

First 3 stages are file-by-file; 4th stage merges them. You can use “file anyFileName” to check out each intermediate file, and cat it if ascii.
–1) preprocessor.
yourSourceCode => preprocessedSource — often 200 time larger.
Both ascii format.
to run this single step — gcc -E
–2) assembler. This is Before compiler.
preprocessedSource => assembledTextFile.
Both ascii format — yes for the assembler!
to run this single step — gcc – S
–3) compiler.
assembledTextFile => individualObjectFile
Ascii -> binary
to run this single step — gcc -c -x assembler
One object file for each original source file.
–4) linker.
individualObjectFiles => singleMergedObjectFile
Now executable.

g++ removes a method if never called@@

I suspect the syntax checker in gcc effectively comments out an (potentially illegal) method if it's never called. In the example below,

1) modification of this->intVar is blatant violation of const “this” but this is invisible to the gcc syntax checker unless there's a call to the method.

2) More obviously, bad2() calls a non-existent method but condoned unless someone calls bad2().

using namespace std;
template struct J{
    J(T & rhs){}
    void violateConstThis(T a) const{
       this->intVar = a; // legal when method is const but no one calls.
    void bad2() const{
    T intVar;
int main()
    int a=22;
    const J j1(a);
    return 0;