7

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:

  • The path includes the environment (example).
  • It is system dependent.
Tom de Geus
  • 5,625
  • 2
  • 33
  • 77
  • 1
    If there is a system environment variable that sets include paths, you can set that when the environment is activated – darthbith Jul 19 '18 at 21:38
  • @darthbith Thanks for your reply. I guess a big deficiency is that there is no such environment variable. I could, of course, introduce my own environment variable, say `${INCLUDEPATH}`. If I were to do that, how can I set it based on the virtual environment? – Tom de Geus Jul 20 '18 at 06:29
  • 2
    https://stackoverflow.com/a/46833531/2449192 – darthbith Jul 20 '18 at 12:03
  • @darthbith Nice, thanks a lot. – Tom de Geus Jul 20 '18 at 12:16

2 Answers2

3

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
Tom de Geus
  • 5,625
  • 2
  • 33
  • 77
2

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}
  • Please add further details to expand on your answer, such as working code or documentation citations. – Community Aug 27 '21 at 11:16
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Dorin Baba Aug 27 '21 at 11:58