0

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!

cconsta1
  • 737
  • 1
  • 6
  • 20
  • 1
    Does [this](https://stackoverflow.com/questions/41542990/while-installing-on-osx-sierra-via-gcc-6-keep-having-fatal-opt-local-bin-l) answers your question? – Rohan Bari Apr 23 '20 at 20:05
  • Hi, no I saw that thread when I was searching for a solution earlier today but it doesn't help. I don't even know what MacPorts are and I don't have a port command on my machine. – cconsta1 Apr 23 '20 at 20:27
  • 1
    It compiles and runs fine on my Mac. I would try `brew rm gcc` and also removing all your other unnecessary versions and then reinstalling with `brew install gcc` and try again. – Mark Setchell Apr 23 '20 at 20:52
  • I tried this as well (`brew rm gcc`) but the compiler won't work. Is there a way to delete all of brew and reinstall maybe? It seems like the problem is that assembler `as` which I never heard of before until now. – cconsta1 Apr 23 '20 at 21:05

2 Answers2

1

I ended up reinstalling all packages using

brew list | xargs brew reinstall

This fixed the problem!

cconsta1
  • 737
  • 1
  • 6
  • 20
1

For anyone else who has stumbled across this problem, you do not need to reinstall all of your brew packages. The troublemaker is cctools, which is no longer in the brew formulae list. If for some reason it is still hanging around on your system, you can either

mv /usr/local/Cellar/cctools{,-backup}

to make sure it is no longer seen by the gcc tool suite installed through homebrew, or you can outright remove it

brew uninstall cctools

I opted for the first, at the moment, because I am not sure what, if anything, removal would break. Once I have confirmed that there are no ill effects caused by not having this installed, I will remove it altogether from my system. That being said, I have confirmed that simply moving the directory takes care of the

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

error being reported when you try and compile something with the GNU compiler on Mac OSX (in my case Catalina, but should be the same for Big Sur and Monterrey).

Will
  • 3,500
  • 4
  • 30
  • 38