c++homebrewmacos-catalinagcc-warninggcc9

Gcc not working on MacOS 10.15.4 Catalina?


I wanted to start writing c++ code again and I just realized that the homebrew version of gcc does not compile any c++, c, or even fortran programs.

For example, I tried to compile the following simple hello_world.cpp program:

#include<iostream>

int main()
{
    std::cout << "Hello World!" << std::endl;
    return 0;
}

using

g++-9 hello_world.cpp

The output I get is:

FATAL:/usr/local/Cellar/cctools/855/bin/../libexec/as/x86_64/as: I don't understand 'm' flag!

I tried installing gcc@8, gcc@7, and compile but I still get the same message.

Moreover, the same error message is shown when I try to compile a hello_world.c program using gcc-9 and a hello_world.f90 program using gfortran-9.

The programs *.c and *.cpp compile fine with the clang and clang++ compilers respectively. I also learned that as is an assembler, and that gcc can output a *.s file using the flag gcc -S but I still don't understand the error message.

I think I exhausted my c++ knowledge and internet search before posting so thank you in advance!


Solution

  • I ended up reinstalling all packages using

    brew list | xargs brew reinstall
    

    This fixed the problem!