Install GCC on Mac OS high sierra

19,042

Any idea on how can I install https://gcc.gnu.org/ standalone on my system?

Generally speaking: Don't. That isn't a standard configuration; Clang is the recommended compiler for current macOS systems.

If you have a very good reason, you can use Homebrew to install GCC (brew install gcc). Keep in mind that it cannot be used to build native macOS applications.

Share:
19,042
Developer
Author by

Developer

Updated on June 04, 2022

Comments

  • Developer
    Developer almost 2 years

    I've already visited the following answer but my question is different.

    Install GNU GCC on mac

    Mac OS ships with Clang and somehow /usr/bin/gcc is linked to Clang tool I assume because of this line.

    gcc
    

    clang: error: no input files

    Any idea on how can I install https://gcc.gnu.org/ standalone on my system?

    gcc --version
    

    Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/c++/4.2.1

    Apple LLVM version 9.0.0 (clang-900.0.38)

    Target: x86_64-apple-darwin17.2.0

    Thread model: posix

    InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

    • haccks
      haccks over 6 years
      Type gcc --version.The error clang: error: no input files shows that GCC is already installed on your system.
    • Developer
      Developer over 6 years
      I've edited my question with the output of the this command, the confusion is, is it gcc or clang compiling my c program? I'd like to work directly with gcc.
    • Saurav Seth
      Saurav Seth over 6 years
      The compiler that comes with XCode is Clang, but it should be compatible with gcc's command line. That's one reason why gcc is an alias to clang. Just curious, but why does it matter?
    • Developer
      Developer over 6 years
      they say gcc is better, stackoverflow.com/questions/8205858/…
    • Admin
      Admin over 6 years
      @Developer The answers on that question are 6 years old. They're no longer accurate.
    • Developer
      Developer over 6 years
      ok, so is Clang good for compiling very small binary from pure vanilla C code? I just don't want anything that has to do with C++, i want pure machine code coming out of C code without any overheads or any of bells and whistles of C++ etc. in either my static/dynamic libraries or application.
    • Developer
      Developer over 6 years
      In fact if by mistake I use any of c++ language constructs or c++ libraries, the compiler should throw errors and do not compile the code, i want to enforce C only code. Whereas I assume Clang will compile both. Please advise.
    • Jonathan Leffler
      Jonathan Leffler over 6 years
      I still do my development on Mac running macOS High Sierra using GCC 7.2.0 compiled from source, using basically the recipe from the cross-referenced question (the versions of GCC and its support libraries have changed; I install to a version-named directory under /opt/gcc rather than $HOME, but that's very malleable (there might even be a case for building it to install under /usr/local). For my purposes, it is useful to have multiple versions of GCC available (I have versions as far back as 4.8.1 on one machine; whether they all work is more negotiable).
    • Jonathan Leffler
      Jonathan Leffler over 6 years
      The only gotcha I've run into recently is that the /usr/include/sys/syslog.h file runs foul of GCC bug 82200. Temporarily, I've worked around it by making a local copy of the header and using that instead of the standard one. That isn't entirely satisfactory. Using Brew or similar is arguably simpler. I'm a stubborn old dinosaur and still like to compile my own versions of GCC.
    • Developer
      Developer over 6 years
      @JonathanLeffler Ok, What's your opinion about the binaries produced from GCC and CLang, which one you think produces more efficient and lightweight, standalone/independent binaries.
    • Developer
      Developer over 6 years
      I understand your point, old is gold. Similarly I'm old fashioned to use vanilla c code only without all the bells of whistles of C++ and any it's compilers, want to get pure simple machine code in binary outputs. Compiling from source is big undertaking for me and I don't have that much experience with tools but perhaps later down the road. Shall I favor GCC over Clang? My objective is to build a static library in plain vanilla C along with unit tests that will be used across Unix, Mac and Windows. @JonathanLeffler would you like to get into chat session?
    • Jonathan Leffler
      Jonathan Leffler over 6 years
      I don't have a view on that. In some ways, Clang is even more modern than GCC. I sometimes compile with both; I don't recall noticing a difference in file sizes big enough to worry about, but I've not looked hard. If I were building for distribution to other people's systems, I'd probably use Clang. In particular with C++, there are support libraries that would have to be installed for true GCC where there wouldn't be a problem with Clang. I do check compilations with both compilers (in 32-bit and 64-bit modes), with lots of warnings enabled. It's one way of checking that the code is portable.
    • Developer
      Developer over 6 years
  • Developer
    Developer over 6 years
    Thanks for the enlightenment. I've some questions since I'm coming back to C after a long time but except language constructs have very basic knowledge of the tools and the architecture. Why I shouldn't work with GCC on macOS, curious.
  • Developer
    Developer over 6 years
    secondly when you say gcc cannot be used to build native macOS applications what does it mean? I won't be able to run a hello world app? confused here. Please also define native apps.
  • Developer
    Developer over 6 years
    My good reason is that I want to build pure vanilla C libraries and apps, the compiler should throw errors if I use any of C++ language constructs or libraries.
  • Admin
    Admin over 6 years
    By "native", I mean a macOS GUI application (i.e, displays windows, has an icon in the Dock -- as opposed to a command-line application which runs in the terminal). And if you really want to avoid C++, you'll have a tough time of that: the macOS dynamic linker -- which is required to launch any program -- is written in C++, as is the XNU kernel.
  • Developer
    Developer over 6 years
    Ok, my scope is limited to command line apps, static libraries (.a files) with some networking. If i understand correctly dynamic linker is just for launching the app, it's not adding anything related to C++ to my static library or app, right?
  • Developer
    Developer over 6 years
    also can you help me choose between Make or CMake build tools considering the reservation I've against C++.
  • Developer
    Developer over 6 years
    also is there a unit testing framework based on Clang, LLVM stack, any recommendations to stay within C only.
  • Admin
    Admin over 6 years
    1) You're posing extra questions in these comments which don't relate to what you initially asked about. Ask a separate question if you have more questions, but keep in mind that software recommendations are off-topic here. 2) Clang is literally just a C/C++ compiler. It doesn't have its own unit testing framework.
  • Admin
    Admin over 5 years
    nvcc fatal : The version ('10.0') of the host compiler ('Apple clang') is not supported make: *** [clock.o] Error 1 -- This good enough for you..?