Tom de Geus
Tom de Geus

Reputation: 5985

Set include-path for header only library installed with conda

I was recently advised to check out conda as a package manager. Unfortunately I don't succeed in finding how to make my compiler find a header-only library installed with conda? Ideally I would like to not having to manually specify a path to my compiler at all.

(The context is that I come from homebrew on macOS, which creates symbolic links on the right locations. Obviously this is what conda avoids. But still, a simple way to compile simple examples would be nice!)


Example

For example, if my code is the one below. Note: this question is meant to be generic, not related to a specific package, nor do I want to have to manually specify again my specific virtual environment.

#include <iostream>
#include <xtensor/xarray.hpp>
#include <xtensor/xio.hpp>

int main()
{
  xt::xarray<double> a
    {{1.0, 2.0, 3.0},
     {2.0, 5.0, 7.0},
     {2.0, 5.0, 7.0}};

  std::cout << a;
}

I have 'installed' the library using

conda create --name example
source activate example
conda install -c conda-forge xtensor-python

Now I would like to compile just with

clang++ -std=c++14 test.cpp

Note that I know that this works:

clang++ -std=c++14 -I~/miniconda3/envs/example/include test.cpp

But I don't think that this is wanted, because:

Upvotes: 8

Views: 7123

Answers (2)

user3020921
user3020921

Reputation: 55

I would rather export CPATH or CPLUS_INCLUDE_PATH variable to add ${CONDA_PREFIX}/include : it would untangle compilation process (compiling test.cpp) from conda environment allowing portability of your compilation process.

CPATH If this environment variable is present, it is treated as a delimited list of paths to be added to the default system include path list. The delimiter is the platform dependent delimiter, as used in the PATH environment variable.

C_INCLUDE_PATH, OBJC_INCLUDE_PATH, CPLUS_INCLUDE_PATH, OBJCPLUS_INCLUDE_PATH These environment variables specify additional paths, as for CPATH, which are only used when processing the appropriate language.

Use https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html?highlight=env#setting-environment-variables to set environment variables.

$ conda env config vars set CPATH=${CONDA_PREFIX}/include:${CPATH}

Upvotes: 3

Tom de Geus
Tom de Geus

Reputation: 5985

At least on unix systems, a solution would be to use

clang++ -std=c++14 -I"${CONDA_PREFIX}"/include test.cpp

thereby "${CONDA_PREFIX}" point to the root of the current conda environment. In this case:

~/miniconda3/envs/example

Upvotes: 3

Related Questions