gcc, g++ builds on macos
On macOS, conda-forge has provided clang, clangxx as the sole compiler
for C and C++ sources. We have also provided gfortran to compile FORTRAN
sources. Unlike other package managers like homebrew we have not
provided gcc nor g++ on macos. The reason to not provide those have been
to avoid incompatibility with the clang based toolchain and also the
maintenance burden. There are two main incompatibilities. First,
clang++ uses libc++ as the standard C++ library and g++ uses
libstdc++ as the standard C++ library. Second, clang uses libomp
as the OpenMP library whereas gcc uses libgomp as the OpenMP library.
Today, we announce the availability of gcc, g++ compilers on macos.
You can install them using
conda install gcc gxx
Currently we support only gcc 15 and will not support gcc 14 or previous versions.
The main difference between these packages and a vanilla gcc installation
or the installation from Homebew is that they use libomp as the default
OpenMP library and libc++ as the default standard C++ library.
This difference makes binaries compiled with gcc, g++ compatible with
binaries compiled with clang, clang++.
Another interesting consequence of the infrastructure work done to enable
this is that this enables cross compilation of C/C++ sources using gcc,
g++ to cross-compile macOS binaries from Linux (previously only clang
supported this) and also cross-compile windows binaries from macOS using
the GCC/MinGW compilers.
To use them in conda-build recipes, you can use
requirements:
build:
- {{ compiler('gcc') }} # [osx]
- {{ compiler('gxx') }} # [osx]
- {{ stdlib('c') }}
You can also do
c_compiler: # [osx]
- gcc # [osx]
c_compiler_version: # [osx]
- 15 # [osx]
cxx_compiler: # [osx]
- gxx # [osx]
cxx_compiler_version: # [osx]
- 15 # [osx]
in conda_build_config.yaml and continue to use the well-established
{{ compiler("c") }} and {{ compiler("cxx") }} macros in the recipe;
be aware that you're then responsible for updating the version roughly once
per year (to keep pace with the rest of conda-forge).
When you are using gcc locally, similar to clang, we make some guesses
about where the macOS SDK is located. This might fail sometimes and setting
the environment variable SDKROOT to the root of the macOS SDK should make
gcc look in that folder.
We also add by default -L $CONDA_PREFIX/lib -Wl,-rpath,$CONDA_PREFIX/lib
when linkingfor local builds with the conda-gcc-specs package that is
installed by deault with gcc package. If you want to avoid that you can
install the gcc-no-conda-specs package alongside gcc.
