Travis CI with Clang 3.4 and C++11

后端 未结 3 596
我在风中等你
我在风中等你 2021-01-30 00:26

Is it possible to get Travis CI working with Clang that is capable of C++11? (I want Clang, not GCC, I already have GCC 4.8 working in Travis CI.) It appears that the version th

相关标签:
3条回答
  • 2021-01-30 00:39

    It appears that the clang developers fixed this when you build in -std=gnu++11 mode.

    Are you able to build with that flag instead of __STRICT_ANSI__?

    • http://llvm.org/bugs/show_bug.cgi?id=13530
    • http://llvm.org/viewvc/llvm-project?view=revision&revision=184476
    0 讨论(0)
  • 2021-01-30 00:47

    There is now a better way to do this.

    sudo: false
    dist: trusty
    language: cpp
    os:
      - linux
    compiler:
      - gcc
      - clang
    install:
    # /usr/bin/gcc is 4.6 always, but gcc-X.Y is available.
    - if [[ $CXX = g++ ]]; then export CXX="g++-4.9" CC="gcc-4.9"; fi
    # /usr/bin/clang has a conflict with gcc, so use clang-X.Y.
    - if [[ $CXX = clang++ ]]; then export CXX="clang++-3.5" CC="clang-3.5"; fi
    addons:
      apt:
        sources:
        - ubuntu-toolchain-r-test
        - llvm-toolchain-precise-3.5 # not sure why we needed this
      packages:
        - gcc-4.9
        - g++-4.9
        - clang-3.5
    

    (The explicit sudo: false will let it build in Docker (for speed) even if you have a pre-docker repo, according to Travis support.)

    Thanks to solarce at Travis support for noticing my error and fixing the docs.

    • http://docs.travis-ci.com/user/apt/
    • http://genbattle.bitbucket.org/blog/2016/01/17/c++-travis-ci/
    • https://github.com/open-source-parsers/jsoncpp/blob/master/.travis.yml (for up-to-date example)
    0 讨论(0)
  • 2021-01-30 00:58

    Here is a part of my .travis.yml files (mostly taken from this file).

    language: cpp
    
    compiler:
      - clang
      - gcc
    
    before_install:
      # g++4.8.1
      - if [ "$CXX" == "g++" ]; then sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test; fi
    
      # clang 3.4
      - if [ "$CXX" == "clang++" ]; then sudo add-apt-repository -y ppa:h-rayflood/llvm; fi
    
      - sudo apt-get update -qq
    
    install:
      # g++4.8.1
      - if [ "$CXX" = "g++" ]; then sudo apt-get install -qq g++-4.8; fi
      - if [ "$CXX" = "g++" ]; then export CXX="g++-4.8"; fi
    
      # clang 3.4
      - if [ "$CXX" == "clang++" ]; then sudo apt-get install --allow-unauthenticated -qq clang-3.4; fi
      - if [ "$CXX" == "clang++" ]; then export CXX="clang++-3.4"; fi
    
    script: 
      - $CXX --version
    

    EDIT because it can be very useful to add libc++ for travis. Up to my knowledge, there is no Linux package for libc++, so one has to compile it "by hand". Do not forget -stdlib=libc++ in CXXFLAGS while compiling with clang.

    install:
      # clang 3.4
      - if [ "$CXX" == "clang++" ]; then sudo apt-get install --allow-unauthenticated -qq clang-3.4; fi
      - if [ "$CXX" == "clang++" ]; then export CXXFLAGS="-std=c++0x -stdlib=libc++"; fi
      - if [ "$CXX" == "clang++" ]; then svn co --quiet http://llvm.org/svn/llvm-project/libcxx/trunk libcxx; fi
    
      - if [ "$CXX" == "clang++" ]; then cd libcxx/lib && bash buildit; fi
      - if [ "$CXX" == "clang++" ]; then sudo cp ./libc++.so.1.0 /usr/lib/; fi
      - if [ "$CXX" == "clang++" ]; then sudo mkdir /usr/include/c++/v1; fi
      - if [ "$CXX" == "clang++" ]; then cd .. && sudo cp -r include/* /usr/include/c++/v1/; fi
      - if [ "$CXX" == "clang++" ]; then cd /usr/lib && sudo ln -sf libc++.so.1.0 libc++.so; fi
      - if [ "$CXX" == "clang++" ]; then sudo ln -sf libc++.so.1.0 libc++.so.1 && cd $cwd; fi
    
      - if [ "$CXX" == "clang++" ]; then export CXX="clang++-3.4"; fi
    
    0 讨论(0)
提交回复
热议问题