3

I have the following files on a linux VM:

gc.h
gc.c
test.c
test.out

I run the command in terminal:

gcc -g test.c gc.c gc.h -o test.out

Everything compiles. I then run the same files (I copied them over) and run the command on my OSX terminal:

gcc -g test.c gc.c gc.h -o test.out

I then get the following error:

clang: error: cannot specify -o when generating multiple output files

Is there a simple reason why I am getting this error? I don't understand as I am not generating multiple files? I also googled this, but couldn't find anything relevant.

I have appreciated your clues. I get now that it has to do with the fact that I am running OSX 10.9 Mavericks and xcode 5.0.2. So now I am in the process of trying to switch over to gcc48. So I thought doing it would be easiest with brew install gcc48. I just did a major update with brew last week and I saw this message:

Error: No available formula for gcc48
Searching taps...
homebrew/versions/gcc48

Anyone see this before? I am somewhat not very experienced with the brew tool. What does this mean? Yes, I googled this, but just don't seem to have a lot of luck today. Then, I found this Homebrew install specific version of formula? and I think I got it working. But not quite sure why the normal command wouldn't work as intended?

Community
  • 1
  • 1
GeekyOmega
  • 1,235
  • 6
  • 16
  • 34

2 Answers2

4

Your problem is that you're trying to compile a header file:

gcc -g test.c gc.c gc.h -o test.out
                   ^^^^

clang is interpreting this as an attempt to precompile the header. While a useful thing to do in general, this isn't compatible with also compiling your application in the same breath.

Remove that from the compiler command line and you'll be fine.

  • 1
    This. Under normal circumstances, don't compile header files. The compiler will understand what you intend to do as long as the file is in the header search path. – SevenBits Dec 13 '13 at 19:55
  • I am considering this the answer as it allows me to send it to another individual without them changing their environment. However, I think in the future I will use gcc48 when having to stay in pure linux environments, but have to develop on a mac. – GeekyOmega Dec 14 '13 at 00:31
2

OSX uses clang not gcc in their gcc command. Just do a gcc --version on both your linux vm and your osx machine and you'll notice that they are different compilers.

You could install the real gcc using brew (e.g., brew install gcc48) and then use that on your osx if you want to get the exact same behavior as on your linux vm.

Christian Fritz
  • 20,641
  • 3
  • 42
  • 71
  • I tried installing gcc48. I get the following error: Error: No available formula for gcc48 Searching taps... homebrew/versions/gcc48 sigh...just one of those days. – GeekyOmega Dec 13 '13 at 19:47
  • While this may be true, this isn't why the OP is having his issue. See the above answer for the correct answer. – SevenBits Dec 13 '13 at 19:54
  • 3
    @GeekyOmega yes, you will need to tap that. I think brew tap homebrew/versions && brew install gcc48 should work. – Christian Fritz Dec 14 '13 at 00:20
  • Thanks. That indeed was the issue with gcc48. Learning things step by step. I gave you some rep for your comments. – GeekyOmega Dec 14 '13 at 00:32