user906357
user906357

Reputation: 4685

Installing GCC on macOS Catalina

I am on macOS Catalina and trying to install GCC by following the instructions here: https://solarianprogrammer.com/2019/10/12/compiling-gcc-macos/

Everything seems to work fine until I try to configure. Then I get the following:

configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details

While trying to fix this I found the following:

MacOS "configure: error: cannot run C compiled programs"

However this answer requires going to the following directory:

/Library/Developer/CommandLineTools

The problem is I do not have CommandLineTools in /Library/Developer/ not even as a hidden file. Trying to fix this I found this

How to compile GCC on macOS Catalina?

but there is now answer here and I do not have nix and don't want to mess with it as it appears to not be very compatible with macOS Catalina. So the question is how can I run the configure?

Upvotes: 7

Views: 33601

Answers (3)

Ernest Lee
Ernest Lee

Reputation: 192

Install GCC on MacOS

learn from above vedio,i use macOX 11.1, install gcc and g++ step:

  1. "brew install gcc", after that, check install success by: "brew info gcc".
  2. "cd /usr/local/bin"
  3. "ls | grep 'gcc'" should see the gcc version you install before, like: gcc-10 or g++-10.
  4. "ln -s gcc-10 gcc" make a symlink from your gcc version to gcc.
  5. close terminal, and open again, input "gcc -v", should see it use gcc now.

If still use clang:

  1. make sure you logout and login again.
  2. use "where gcc" or "which gcc" to check your gcc symlink create success.
  3. "echo $PATH", make sure "/usr/local/bin" show before "/usr/bin" on your PATH, if not, change it on your ~/.zshrc or ~/.bashrc

Upvotes: 6

user906357
user906357

Reputation: 4685

Probably not the elegant answer, but it worked. I was able to find the header files needed using $(xcrun --show-sdk-path) I then copied them all to /usr/local where the gcc location was expecting them to be. Now all works.

Upvotes: 1

l'L'l
l'L'l

Reputation: 47169

First you need to install the Command-Line tools.

$ xcode-select --install

Then you probably want to install the headers from a specific .pkg in Terminal:

$ open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

(yours is 10.15, so):

$ open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.15.pkg

After finishing the installation you should have the headers you need to compile with your GCC.

Upvotes: 2

Related Questions