是否有可能让Travis CI与能够使用C ++ 11的Clang合作? (我想要Clang,而不是GCC,我已经在Travis CI中使用了GCC 4.8。)看来预安装的版本不支持C ++ 11。我安装任何较新版本的所有尝试都以failing because of this结束:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/move.h:57:
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/type_traits:269:39: error:
use of undeclared identifier '__float128'
struct __is_floating_point_helper<__float128>
我见过-D__STRICT_ANSI__
trick,但与我的其他事情发生了冲突。
是否可以让它正常工作?另请参阅我的.travis.yml。
答案 0 :(得分:61)
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
(根据Travis的支持,显式sudo: false
将使它在Docker(速度)中构建,即使你有一个预泊坞回购站。)
感谢Travis支持的solarce注意到我的错误并修复了文档。
答案 1 :(得分:33)
以下是我的.travis.yml文件的一部分(主要来自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
编辑,因为为travis添加libc ++非常有用。据我所知,libc ++没有Linux软件包,因此必须“手动”编译它。使用clang编译时,不要忘记CXXFLAGS中的 -stdlib = libc ++ 。
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
答案 2 :(得分:1)
当你在-std=gnu++11
模式下构建时,clang开发人员似乎已经解决了这个问题。
您是否可以使用该标志而不是__STRICT_ANSI__
进行构建?