Skip to content

Installing conos for Mac OS

evanbiederstedt edited this page Mar 1, 2022 · 6 revisions

The package conos is currently on CRAN. We recommend that Mac OS users install via the binaries provided there, using the command:

install.packages('conos')

This is the way we would recommend users install conos.

Note: If you are still running into the error Library not loaded: @rpath/igraph.so, please check the instructions here: https://github.com/kharchenkolab/leidenAlg/wiki/Installing-leidenAlg-for-Mac-OS


Before conos was on CRAN, users had to install the package from source, either using

devtools::install_github('kharchenkolab/conos')

or cloning the repo and installing via

git clone https://github.com/kharchenkolab/conos.git
cd conos
R CMD build .
R CMD install conos*.tar.gz

When installing from source, the R package (with the associated C++ code) must compile locally. If you are an OS X user, it's highly likely that you're using the gcc and clang built by Xcode. This results in some frustration for users trying to install conos. For instance, Apple explicitly disabled OpenMP support in compilers that they ship in Xcode:

$ clang -c test_omp.c -fopenmp
clang: error: unsupported option '-fopenmp'

Note: OpenMP (Open Multi-Processing) is a library within Conos which supports multi-platform shared-memory multiprocessing programming in C, C++, and Fortran.

There are some work arounds if you google solutions, e.g. this Stack Overflow post

Therefore, we recommend installing compilers and linking to them appropriately.

(This procedure has been tested on Mac OS Catalina, Version 10.15.5.)

Using Homebrew, install the following:

brew install gcc gfortran llvm

Then, include the following in your ~/.zshrc (or ~/.bash_profile):

export PATH="/usr/local/opt/llvm/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/llvm/lib"
export CPPFLAGS="-I/usr/local/opt/llvm/include"

Then, add the compiler paths to your ~/.R/Makevars file.

XCBASE:=$(shell xcrun --show-sdk-path)
LLVMBASE:=$(shell brew --prefix llvm)
GCCBASE:=$(shell brew --prefix gcc)
GETTEXT:=$(shell brew --prefix gettext)

CC=$(LLVMBASE)/bin/clang -fopenmp
CXX=$(LLVMBASE)/bin/clang++ -fopenmp
CXX11=$(LLVMBASE)/bin/clang++ -fopenmp
CXX14=$(LLVMBASE)/bin/clang++ -fopenmp
CXX17=$(LLVMBASE)/bin/clang++ -fopenmp
CXX1X=$(LLVMBASE)/bin/clang++ -fopenmp

CPPFLAGS=-isystem "$(LLVMBASE)/include" -isysroot "$(XCBASE)"
LDFLAGS=-L"$(LLVMBASE)/lib" -L"$(GETTEXT)/lib" --sysroot="$(XCBASE)"

FC=$(GCCBASE)/bin/gfortran -fopenmp
F77=$(GCCBASE)/bin/gfortran -fopenmp
FLIBS=-L$(GCCBASE)/lib/gcc/9/ -lm

(If you do not have a ~/.R/Makevars file, make one with mkdir .R; touch Makevars.)

Once conos is available via CRAN, Mac OS users will be able to install the binary and avoid these complications. Until then, this solution should allow users to install conos on Mac OS.

Clone this wiki locally