How to use the gcc compiler in the mac terminal instead of clang - xcode

Is there a way to change the compiler to gcc from clang? I have the command line tools installed and am trying to use the terminal to compile instead of xcode itself.

For MacPorts use:
port select --set gcc <group>, <version>
. . as detailed in this answer.
For Homebrew use:
Brew link and brew unlink the package versions that you prefer to use. Note that an "unlinked" package is still installed and usable from /usr/local/opt//, it's just not in the default path.

You can install gcc using any ports system (e.g., MacPorts, http://www.macports.org/)

Related

Ubuntu: cgo: C compiler "gcc-11" not found: exec: "gcc-11": executable file not found in $PATH

I am using Ubuntu 20.04, and I installed Go using Homebrew.
The version of Go is go 1.19.
When I run my application with go run . or go build ., this error comes up:
# github.com/mattn/go-sqlite3
cgo: C compiler "gcc-11" not found: exec: "gcc-11": executable file not found in $PATH
I have tried running
sudo apt install gcc
but the terminal tells me that gcc is already the newest version (4:9.3.0-1ubuntu2).
When I run gcc -v
the terminal tells me gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
And I have already run apt update and apt upgrade already, and then reinstall gcc, but it's still version 9.4.0
My question is how do I install gcc-11? Or is it not supported in Ubuntu 20.04? Or should I not use go 1.19?
Thanks
The go developers provide a simple way to manage multiple go versions at once: https://go.dev/doc/manage-install
It should not be too hard to explore if this is a Homebrew artifact, or something generic to go, or a specific version of go on your system.
You might also look at the output of go env which should list configured defaults for various dependencies. You are looking for something like CC=gcc in the output.

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?
Install GCC on MacOS
learn from above vedio,i use macOX 11.1, install gcc and g++ step:
"brew install gcc", after that, check install success by: "brew info gcc".
"cd /usr/local/bin"
"ls | grep 'gcc'" should see the gcc version you install before, like: gcc-10 or g++-10.
"ln -s gcc-10 gcc" make a symlink from your gcc version to gcc.
close terminal, and open again, input "gcc -v", should see it use gcc now.
If still use clang:
make sure you logout and login again.
use "where gcc" or "which gcc" to check your gcc symlink create success.
"echo $PATH", make sure "/usr/local/bin" show before "/usr/bin" on your PATH, if not, change it on your ~/.zshrc or ~/.bashrc
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.
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.

Installing gfortran via macports on Mac OS high sierra

My supervisor has asked that I install a fortran compiler on my mac and suggested using MacPorts to install gcc6. I have tried to install gcc6 a number of times but each time it doesn't seem to come with gfortran. No matter what I do I cannot seem to figure out what is going on and how to get around it.
Any hep on the matter would be greatly appreciated.
Here is the command used to install gcc:
sudo port install gcc6
MacPorts allows you to have multiple versions of gcc installed. Before you get gfortran executable you have to select the default version.
First - install gcc:
sudo port install gcc9
After this command you will have gfortran under gfortran-mp-9 alias. To make gfortran-mp-9 the default and make it reachable via gfortran command do:
sudo port select --set gcc mp-gcc9
The examples above assumed gcc9, but you might need adjust the above gcc version to the one you need to work with.
With macports the correct command to install fortran would be
sudo port install gcc6 +gfortran
This will install gfortran. You may want to refer to the gfortran manual along with other Fortran references you may be using.
Note: You may choose some other version of gcc, of course. You can search for which versions are available on the macports site.

how to install libX11 on OSx 10.9?

I am trying to install ROOT (cern.root.ch). When I run ./configure , I get a message that libX11 is missing and must be installed.
I did some research and found that I need to install
) XQuartz (I already have the latest version.)
) Command line tools in Xcode.
I tried installing Command Line Tools from apple's developer website. The installation goes through smoothly but how do I know whether it has been installed? I still get libX11 missing error with root's configure command.
I also tried xcode-select --install and it once went through smoothly and then later again gives error saying this package is no longer maintained - or something of that sort.
I understand I may have multiple installations... But I am still facing the problem of not having libX11 and not being able to install ROOT.
Thanks,
Hershal.
This link and the one referenced in it suggests you use homebrew (brew) to install it
$ ruby <(curl -fsS https://raw.github.com/mxcl/homebrew/go)
$ brew doctor
Remember to add the Homebrew directory to your PATH by adding the directory (found with brew --prefix) to your .bashrc, .zshrc or whatever shell file you’re using (.bashrc is the OS X default). We’ll also add the XQuartz binaries to the PATH in case anything needs them in the future.
export PATH=/usr/local/bin:/opt/X11/bin:$PATH
Start a new Terminal session to pick up the changes.
Now that Homebrew is installed, we can use it to install the required dependencies. Each may take some time as Homebrew generally compiles from source.
$ brew install gfortran # Fortran compiler
$ brew install python # Python interpreter
$ brew install pcre # Regular Expressions library
$ brew install fftw # Fast Fourier Transforms
$ brew install cmake # Cross-platform make
install root
$ brew tap homebrew/science
$ brew install --with-cocoa root
You don't say whether you have installed XCode as well as the commandline tools but I think you will need it

<omp.h> library isn't found in the GCC version (4.2.1) in Mavericks

I have a problem with GCC. I want to update it to a new version, from the 4.2.1, to program with parallel programming. However, in this version there is no library . How can I download an updated version?
The error that the terminal give me is:
omp_hello.c:11:10: fatal error: 'omp.h' file not found
#include <omp.h>
^
1 error generated.
download gcc-4.9-bin.tar.gz download or newer from
http://hpc.sourceforge.net/:
http://prdownloads.sourceforge.net/hpc/gcc-4.9-bin.tar.gz
cd to your downloads folder and un-gzip
the archive gunzip gcc-4.9-bin.tar.gz (Google Chrome would do that
automatically)
in the same folder run sudo tar -xvf gcc-4.9-bin.tar -C / - this will place new executable to /usr/local/bin
add the following to ~/.bash_profile: export PATH=/usr/local/bin:$PATH
open new terminal and run which gcc. This should point to /usr/local/bin/gcc
I got this message when I tried to reinstall GCC via Homebrew.
GCC has been built with multilib support. Notably, OpenMP may not work:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60670
If you need OpenMP support you may want to
brew reinstall gcc --without-multilib
So, if you have Homebrew installed, you could try (on the terminal):
brew reinstall gcc --without-multilib
This process may take a while !
According to this thread on apple's forums, try using gcc-4.9-bin.tar .
First install the gcc-4.9 and type "xcode-select --install" on your terminal.
Then, use "/usr/local/bin/gcc " as compiler.
I solve it just adding aliases to .bash_profile
# Aliases in order to use brew gcc
alias gcc='gcc-5'
alias cc='gcc-5'
alias g++='g++-5'
alias c++='c++-5'

Resources