7

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?

user906357
  • 4,575
  • 7
  • 28
  • 38

3 Answers3

5

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
Ernest Lee
  • 182
  • 3
  • 10
2

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.

l'L'l
  • 44,951
  • 10
  • 95
  • 146
  • 1
    xcode-select --install gives me xcode-select: error: command line tools are already installed, use "Software Update" to install updates, but I have already updated everything. – user906357 Jan 30 '20 at 00:58
  • No luck, I tried then tried the xcode-select --install again and the result is the same. Still the only thing in my Developer directory is CoreSimulator, XCTestDevices and Xcode – user906357 Jan 30 '20 at 03:40
  • Well there's a couple more things you can try. The first being `xcode-select -switch /Applications/Xcode.app`, also try [downloading the Command-Line tools `.dmg`](https://download.developer.apple.com/Developer_Tools/Command_Line_Tools_for_Xcode_11.3/Command_Line_Tools_for_Xcode_11.3.dmg) from the Apple Developer site and install it manually (must be logged in). – l'L'l Jan 30 '20 at 05:19
  • 1
    Okay, I now have CommandLineTools, however the directory Packages is not there. I deleted CommandLineTools and reinstalled it and still the same. I'm guessing the answer may be in the link you gave to apple, but I no longer have a developer account. Is that the only place I can get the packages folder? – user906357 Jan 30 '20 at 19:22
  • @user906357: It doesn't cost anything to make an account. Once you do follow the link in my comment, – l'L'l Jan 30 '20 at 19:36
  • 1
    I also do not have a `Packages` directory. I have `/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk`. I installed the command-line tools with `xcode-select --install` and then again via `Command_Line_Tools_for_Xcode_11.4.1.dmg`. Install is "succesful", but same thing: no `Packages` directory. Any suggestions? – PatrickT May 18 '20 at 08:07
1

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.

user906357
  • 4,575
  • 7
  • 28
  • 38