"error: '::timespec_get' has not been declared" with conda root package

Hello,

I am having trouble compiling a application against the conda ROOT packages. It fails with error: '::timespec_get' has not been declared. Has someone seen this before?

I create the conda environment in the following way:

conda create -n myroot
conda activate myroot
conda install root

The exammple code is very simple.

main.cpp:

#include <TFile.h>

int main(int argc, char* argv[]) {
  TFile::Open("test.root");

  return 0;
}

CMakeLists.txt

CMAKE_MINIMUM_REQUIRED(VERSION 3.10)

PROJECT(conda_test)

FIND_PACKAGE(ROOT REQUIRED)
INCLUDE(${ROOT_USE_FILE})

ADD_EXECUTABLE(main main.cpp)
TARGET_LINK_LIBRARIES(main ${ROOT_LIBRARIES})

However compilng this I see:

Scanning dependencies of target main
[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
In file included from /global/cfs/cdirs/atlas/kkrizka/conda/myroot/x86_64-conda-linux-gnu/include/c++/9.3.0/chrono:41,
                 from /global/cfs/cdirs/atlas/kkrizka/conda/myroot/x86_64-conda-linux-gnu/include/c++/9.3.0/condition_variable:38,
                 from /global/cfs/cdirs/atlas/kkrizka/conda/myroot/include/ROOT/TRWSpinLock.hxx:19,
                 from /global/cfs/cdirs/atlas/kkrizka/conda/myroot/include/TFile.h:38,
                 from /global/homes/k/kkrizka/roottest/main.cpp:1:
/global/cfs/cdirs/atlas/kkrizka/conda/myroot/x86_64-conda-linux-gnu/include/c++/9.3.0/ctime:80:11: error: '::timespec_get' has not been declared
   80 |   using ::timespec_get;
      |           ^~~~~~~~~~~~


Karol Krizka

Hi @kkrizka ,
this is likely a “system env vs. conda env” mismatch. First of all could you try to also install cmake and make in the conda environment and use those to compile the code?

If that doesn’t work I’ll take a closer look.

Cheers,
Enrico

Hi @eguiraud,

I tried installing make and cmake within conda. It did not change the result.

To confirm that they (and gcc) are being picked up from my conda environment:

(/global/cfs/projectdirs/atlas/kkrizka/conda/myroot) [kkrizka@cori07 build]$ which cmake
/global/cfs/projectdirs/atlas/kkrizka/conda/myroot/bin/cmake
(/global/cfs/projectdirs/atlas/kkrizka/conda/myroot) [kkrizka@cori07 build]$ which make
/global/cfs/projectdirs/atlas/kkrizka/conda/myroot/bin/make
(/global/cfs/projectdirs/atlas/kkrizka/conda/myroot) [kkrizka@cori07 build]$ which gcc
/global/cfs/projectdirs/atlas/kkrizka/conda/myroot/bin/gcc


Karol Krizka

I could not reproduce on my system. Could it be that you get root from conda-forge but the compilation toolchain from the default channels?

In the meanwhile I’m setting up a Dockerfile so we can run the exact same thing.

Cheers,
Enrico

Here’s the tentative reproducer (that works instead of breaking, for now): https://gitlab.cern.ch:8443/eguiraud/repro_forum_conda_root

You can run docker build -t repro-conda-root . inside the repo and it will create a conda env with ROOT inside the container, then try to compile a program using your CMakeLists.txt.

What am I doing differently?

Hi @eguiraud,

Thank you for looking into it. As far as I can tell, your docker image does exactly the same as I do. I also managed to get everything to work when manually typing commands into a continuumio/anaconda3 container.

So it must be something from my system leaking into the conda environment. I will try to investigate further.

Given that this is specific to my setup, I will try to investigate further myself. But I put some extra notes I found below for completeness.

I got one more hint. When instantiating a TH1F instead of TFile in main.cpp, the compilation works. However the linker fails with

[ 50%] Linking CXX executable main
/global/cfs/cdirs/atlas/kkrizka/conda/myroot/bin/../lib/gcc/x86_64-conda-linux-gnu/9.3.0/../../../../x86_64-conda-linux-gnu/bin/ld: /global/cfs/projectdirs/atlas/kkrizka/conda/myroot/lib/libstdc++.so: undefined reference to `aligned_alloc@GLIBC_2.16'
/global/cfs/cdirs/atlas/kkrizka/conda/myroot/bin/../lib/gcc/x86_64-conda-linux-gnu/9.3.0/../../../../x86_64-conda-linux-gnu/bin/ld: /global/cfs/projectdirs/atlas/kkrizka/conda/myroot/lib/libpcre.so.1: undefined reference to `memcpy@GLIBC_2.14'
/global/cfs/cdirs/atlas/kkrizka/conda/myroot/bin/../lib/gcc/x86_64-conda-linux-gnu/9.3.0/../../../../x86_64-conda-linux-gnu/bin/ld: /global/cfs/projectdirs/atlas/kkrizka/conda/myroot/lib/libstdc++.so: undefined reference to `clock_gettime@GLIBC_2.17'

Line 80 of the ctime header from the original error is potentially also glibc related.

#if __cplusplus >= 201703L && defined(_GLIBCXX_HAVE_TIMESPEC_GET)
#undef timespec_get
namespace std
{
  using ::timespec;
  using ::timespec_get;
} // namespace std
#endif

I’ve also attached the conda list output in my failing environment (myroot.txt (12.8 KB)). The compilers do seem to get picked up from conda-forge.

One more thing worth noting is that root via conda used to work in my setup. This problem only came up recently after I updated the root package. Downgrading root did not fix it though.


Karol Krizka

(pinging @chrisburr in case he has an idea)

I managed to get things working. The problem indeed seemed to be default channel vs conda-forge. I mispoke earlier. Only package names cxx-compiler and compilers were comming from conda-forge. The gcc_linux-64 package was from the default channel.

The following lines in my .condarc seem to be the culprit. Removing them causes gcc_linux-64 to come from conda-forge and my root application to compile.

channels:
  - defaults
  - conda-forge

Thank you very much for all the help!


Karol Krizka

I wanted to let you know that I came across the exact same issue, and that this discussion solved everything!
In my case, I run conda upgrade -c conda-forge --all to have access to all packages via the conda-forge channel.
Thank you!

2 Likes

I had exactly the same error message recently and searching on the forum led me here. Thanks @bfontana your command to upgrade the packages via conda-forge. It immediately solves my problem! I hope this thread will help people like me who are newbies to conda

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.