I'm trying to install Riak from source on macOS (https://docs.riak.com/riak/kv/2.2.3/setup/installing/mac-osx.1.html#installing-from-source).
There is a note:
Riak will not compile with Clang. Please make sure that your default C/C++ compiler is GCC
How do I find out which compiler is the default and how to change it?
macOS Catalina (10.15.4), which command prints:
$ which clang
/usr/bin/clang
$ which gcc
/usr/bin/gcc
On macOS Catalina (and prior versions, and most likely subsequent versions too), there are two aspects to the problem and some suggested solutions.
What is the name of the compiler used by
makeby default?This shows that the names used by
makeareccandc++. Those are not obviouslyclangorclang++, but neither are they obviouslygccandg++.Which compiler is it really?
Which compiler really lives behind the names
cc,c++,gcc,g++,clang, andclang++? We can check which compiler these really are by getting them to identify their version:As you can see, the versions installed in
/usr/binare all the same compiler, and that compiler isclangorclang++.This was run on a machine with macOS Mojave 10.14.6 and XCode 11.3.1. The latest version of XCode — 11.4.1 — is only available on Catalina. However, the general conclusion is the same — all the C and C++ compilers are really
clangandclang++in disguise.How do you get GNU GCC onto your machine?
How do you get a real GNU GCC — a real GCC, not
clangin disguise — onto your machine?Be aware that Apple has taken to hiding the system header files miles out of the way (not in
/usr/include— and you can't modify that part of the file system to add a symlink to where they've hidden them):(You mean you couldn't guess that? Me neither!)
How do you change the default compiler?
Once you have GCC installed somewhere appropriate, you need to ensure you use the 'real' GCC and not the 'fake' in
/usr/bin. You do that in part by ensuring that the bin directory for the 'real' GCC occurs on your PATH before/usr/bin. I have GCC 9.3.0 installed under/opt/gcc/v9.3.0, so/opt/gcc/v9.3.0/binappears on my PATH long before/usr/bindoes.You also need to ensure that the configuration for
riak(the software you're installing) uses the correct compilers. If there's a./configurescript, run it with the correct path specified for the compilers. For example, I might use:You can also set these values as environment variables.
If it uses
cmakeor some other configuration package, you'll need to consult the installation instructions. That's usuallyREADMEor sometimesINSTALL.See also (increasingly older posts):