Skip to content

C++ and Clang and Trusty: this is what your environment should do #9550

@svenevs

Description

@svenevs

Hello,

If you follow the official directions for clang, build failures will ensue because the G++ headers will get used (rather than clang's):

/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/complex:539:18: error: no matching member function for call to 'real'
    { return __z.real(); }

While trying to figure this out, I noticed nice little undocumented gem at the beginning of my build logs:

$ export CXX=clang++
$ export CC=clang
$ clang --version
clang version 5.0.0 (tags/RELEASE_500/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/clang-5.0.0/bin

This is definitely coming from Travis, AKA the relevant tools are already installed. So unless clang@5.0.0 is a problem, virtually all of the Clang specific instructions are incorrect / incomplete / outdated, since Travis appears to have a full llvm installation here.

In other words, by me saying compiler: clang, I already have clang@5.0.0 directly available. Wherever the code is that sets the above CXX and CC, all you need to do is this instead:

export CXX="/usr/local/clang-5.0.0/bin/clang++"
export CC="/usr/local/clang-5.0.0/bin/clang"
export CPATH="/usr/local/clang-5.0.0/include/c++/v1"
export LD_LIBRARY_PATH="/usr/local/clang-5.0.0/lib"

By simply putting this in my before_install, all build failures are gone with clang. Namely, I do have access to libc++ and libc++-abi, and the clang headers are used rather than the system G++ headers.

I do not need to install any extra packages, just need the right dev environment flags setup.

I am happy to help update the clang documentation, but wanted to see what other users thought here. For reference, this is a

  • CMake based project, but none of the above are CMake specific
  • sudo: false on a dist: trusty worker

I feel that if the above four variables are set correctly, the load on travis for users wanting to test with clang will be significantly reduced -- the image already has everything we need! I tried to find out where this stuff is set and open a PR...but got really turned around...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions