How to use gcc from anaconda? When I compile files, it complains about not finding system headers like stdio.h

Viewed 7254

I'm using miniconda to be able to create a portable environment that can can carry it owns dependencies such as GCC within a software application.

I did something some simple like

conda install gcc
conda install libgcc

and tried using conda's gcc to compile a simple file like

#include <stdio.h>

int main() {
  print('hai world');
}

which would complain,

fatal error: 'stdio.h' file not found

I'm doing this within my MacBook and I don't want to install Xcode developer tools to get access to gcc and its system headers because I want this to be as portable as possible.

I also tried conda-build with conda recipes for gcc-4.8, but that ended up complaining that I need cc (C compiler) which comes with Xcode.app that I don't want to install.

Do you have any ideas how to use gcc with system headers through conda so that I can compile files with system headers like stdio.h ?

1 Answers

What worked for me was:

  1. Starting from scratch, install a recent version of miniconda. In particular conda 4.6 switched to a much better SAT solver for the dependency graph.
  2. set channel_priority to false (conda config --set channel_priority false)
  3. Minimize the set of channels. You probably only REALLY need defaults and conda-forge (optionally adding a few packages ad hoc from other channels, see below). So you can run conda config --add channels defaults; conda config --add channels conda-forge.
  4. Avoid having one massive environment for different needs. Instead, create an environment per project/tool.

Your .condarc file should look like this:

$ cat ~/.condarc
channels:
  - conda-forge
  - defaults
channel_priority: disabled

If you need to install packages outside of defaults and conda-forge, you should try installing only them with a channel prefix, and let conda take their dependencies from defaults and conda-forge, e.g. conda install bioconda::snakemake

Related