Building ROOT with clang+libc++ on Ubuntu


ROOT Version: 6.16.00
Platform: Ubuntu 18.04
Compiler: Clang+libcxx


Hey!
In our CI we build our project with clang from LCG in one job. We ran into a bug which is most likely due to Clang and GNU’s libstdc++ not really being compatible (which I was unaware of). As far as I know, libc++ is not part of any LCG release. That’s why I’m trying to build ROOT+G4+DD4hep using libc++ separately.

I’m using a Ubuntu docker container using Clang+libc++. Compiling with Clang only works, but I run into trouble later (in the DD4hep build) when (I believe) ROOT is generating C++ code querying the libstdc ++ ABI, which fails when that code is compiled using libc++. On the other hand, when I enable -Dlibcxx=ON, the ROOT build itself fails when generating G__Core.cxx with this:

Warning in cling::IncrementalParser::CheckABICompatibility():
  Failed to extract C++ standard library version.
Warning in cling::IncrementalParser::CheckABICompatibility():
  Possible C++ standard library mismatch, compiled with _LIBCPP_ABI_VERSION '1'
  Extraction of runtime standard library version was: ''
In file included from input_line_9:153:
In file included from /root_build/include/TClassEdit.h:29:
/usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/cxxabi.h:128:3: error: exception specification in declaration does not match previous declaration
  __cxa_atexit(void (*)(void*), void*, void*) _GLIBCXX_NOTHROW;
  ^
input_line_2:2:16: note: previous declaration is here
extern "C" int __cxa_atexit(void (*f)(void*), void*, void*) ;

(I guess this is only the first instance for which it would fail, I guess all the generated code is affected).

The Building ROOT page mentions that -Dlibcxx is “(MacOS X only, for the time being)”, could that be the problem here?

I used clang master instead of clang 7 as you commented in person, but my ROOT built successfully. Here’s the full command line I used for CMake:

$ cmake  -DCMAKE_BUILD_TYPE="Release" -DCMAKE_CXX_COMPILER="clang++" -DCMAKE_CXX_FLAGS="-march=native" -DCMAKE_CXX_STANDARD="17" -DCMAKE_C_COMPILER="clang" -DCMAKE_C_FLAGS="-march=native" -Dasimage="OFF" -Dastiff="OFF" -Dbuiltin_afterimage="OFF" -Dbuiltin_ftgl="OFF" -Dbuiltin_glew="OFF" -Dclad="OFF" -Ddavix="OFF" -Dfftw3="OFF" -Dfitsio="OFF" -Dimt="OFF" -Dlibcxx="ON" -Dmysql="OFF" -Dopengl="OFF" -Doracle="OFF" -Dpgsql="OFF" -Dpythia6="OFF" -Dpythia8="OFF" -Dpython="OFF" -Droofit="OFF" -Droot7="OFF" -Dsqlite="OFF" -Dtmva="OFF" -Dtmva-cpu="OFF" -Dtmva-gpu="OFF" -Dtmva-pymva="OFF" -Dvc="OFF" -Dvdt="OFF" -Dx11="OFF" -Dxft="OFF" -Dxrootd="OFF" /home/amadio/src/root -G Ninja

I only got this warning:

[364/365] Generating etc/allDict.cxx.pch
warning: argument unused during compilation: '-stdlib=libc++'
warning: argument unused during compilation: '-stdlib=libc++'
[365/365] Generating tutorials/hsimple.root

Processing hsimple.C...
hsimple   : Real Time =   0.05 seconds Cpu Time =   0.05 seconds
(TFile *) 0x205b890

I will investigate if it’s a problem or not.

Hm, ok. I tried to build with your exact flags, which gives me the same error I’ve had before. Can you tell me what your setup and environment is that you’re building in?
I’m still getting

Warning in cling::IncrementalParser::CheckABICompatibility():
  Failed to extract C++ standard library version.
Warning in cling::IncrementalParser::CheckABICompatibility():
  Possible C++ standard library mismatch, compiled with _LIBCPP_ABI_VERSION '1'
  Extraction of runtime standard library version was: ''
In file included from input_line_9:149:
In file included from /root_build/include/TClassEdit.h:29:
/usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/cxxabi.h:128:3: error: exception specification in declaration does not match previous declaration
  __cxa_atexit(void (*)(void*), void*, void*) _GLIBCXX_NOTHROW;
  ^
input_line_2:2:16: note: previous declaration is here
extern "C" int __cxa_atexit(void (*f)(void*), void*, void*) ;

/usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/cxxabi.h sounds to me like it’s still including the GNU cxxabi.h file at some point.

I’m using a binary release of clang7 for Ubuntu, since building clang from scratch takes ages. But I guess I could give it a shot with clang-master, if you think that might be the cause of my build failure.

On the other hand I have a Dockerfile that would probably reproduce the error I’m seeing on your end, if that would be of interest to you, and you’re willing to spend the time to investigate.

Yes, the inclusion of GCC headers seems to be the problem in your case. The mismatch seems to be due to that. Feel free to send me the Dockerfile you have, but I’m afraid I won’t have time to debug this soon, as I will go on vacations soon for several weeks. You may be able to fix your issue by checking which options cause GCC headers to be used with clang. I don’t think that the problem is in ROOT, as I didn’t do anything special to get it to work.

Sure, no problem.

The Dockerfile goes like:

FROM ubuntu:18.04

SHELL ["/bin/bash","-c"]

RUN apt-get update && apt-get install -y \
  xz-utils \
  build-essential \
  curl \
  rsync \
  libeigen3-dev \
  libexpat-dev \
  libxerces-c-dev \
  python \
  python-dev \
  git \
  && rm -rf /var/lib/apt/lists/*

# install clang
RUN curl -SL http://releases.llvm.org/7.0.1/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-18.04.tar.xz \
  | tar -xJC . \
  && mv clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-18.04 clang_7.0.1 \
  && rsync -rv --links /clang_7.0.1/ /usr/local/ && rm -rf /clang_7.0.1

## install cmake
RUN curl -SL https://github.com/Kitware/CMake/releases/download/v3.13.4/cmake-3.13.4-Linux-x86_64.tar.gz \
    | tar -xzC . \
    && mv cmake-3.13.4-Linux-x86_64 cmake-3.13.4 \
    && rsync -rv --links /cmake-3.13.4/ /usr/local/ && rm -rf /cmake-3.13.4

ENV CXX=clang++ CC=clang

# boost
RUN export BOOST_VERSION="1.69.0" && export BOOST_VERSION_=${BOOST_VERSION//./_} && \
    curl -SL boost-${BOOST_VERSION_}.tar.gz http://downloads.sourceforge.net/project/boost/boost/${BOOST_VERSION}/boost_${BOOST_VERSION_}.tar.gz \
    | tar -xzC . && \
    cd boost_${BOOST_VERSION_}/ && \
    ./bootstrap.sh --prefix=/usr/local/ --with-toolset=clang --with-libraries=program_options,test && \
    ./b2 clean && \
    ./b2 toolset=clang cxxflags="-std=c++17 -stdlib=libc++" linkflags="-stdlib=libc++" --prefix=/usr/local -j $(nproc) stage release && \
    ./b2 install toolset=clang cxxflags="-std=c++17 -stdlib=libc++" linkflags="-stdlib=libc++" --prefix=/usr/local && \
    cd .. && rm -r boost_${BOOST_VERSION_}

ENV LD_LIBRARY_PATH=/usr/local/lib
RUN curl -SL https://root.cern/download/root_v6.16.00.source.tar.gz \
    | tar -xzC .
RUN mkdir root_build && cd root_build \
    && cmake ../root-6.16.00 \
         -DCMAKE_BUILD_TYPE="Release" \
         -DCMAKE_CXX_COMPILER="clang++" \
         -DCMAKE_CXX_FLAGS="-march=native" \
         -DCMAKE_CXX_STANDARD="17" \
         -DCMAKE_C_COMPILER="clang" \
         -DCMAKE_C_FLAGS="-march=native" \
         -DCMAKE_INSTALL_PREFIX=/usr/local \
         -Dasimage="OFF" \
         -Dastiff="OFF" \
         -Dbuiltin_afterimage="OFF" \
         -Dbuiltin_ftgl="OFF" \
         -Dbuiltin_glew="OFF" \
         -Dclad="OFF" \
         -Ddavix="OFF" \
         -Dfftw3="OFF" \
         -Dfitsio="OFF" \
         -Dimt="OFF" \
         -Dlibcxx="ON" \
         -Dmysql="OFF" \
         -Dopengl="OFF" \
         -Doracle="OFF" \
         -Dpgsql="OFF" \
         -Dpythia6="OFF" \
         -Dpythia8="OFF" \
         -Dpython="OFF"\
         -Droofit="OFF" \
         -Droot7="OFF" \
         -Dsqlite="OFF" \
         -Dtmva="OFF" \
         -Dtmva-cpu="OFF" \
         -Dtmva-gpu="OFF" \
         -Dtmva-pymva="OFF" \
         -Dvc="OFF" \
         -Dvdt="OFF" \
         -Dx11="OFF" \
         -Dxft="OFF" \
         -Dxrootd="OFF" \
   && make -j$(nproc)

Thank you for the Dockerfile. I will try it and let you know if I find what could be the problem.

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