SET(CMAKE_SYSTEM_NAME Linux) SET(CMAKE_SYSTEM_VERSION 1) SET(CMAKE_C_COMPILER /opt/clang7/bin/clang) SET(CMAKE_CXX_COMPILER /opt/clang7/bin/clang++) SET(CMAKE_FIND_ROOT_PATH /opt/clang7) SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
我将CMake配置称为cmake -DCMAKE_TOOLCHAIN_FILE = .. / cmake / clang7-ci.cmake ..它似乎从工具链中拾取正确的clang和clang.我可以在CMake的配置输出中看到它们:
— The C compiler identification is Clang 7.0.1
— The CXX compiler identification is Clang 7.0.1
— Check for working C compiler: /opt/clang7/bin/clang
— Check for working C compiler: /opt/clang7/bin/clang — works
所以,我假设它正确地使用了toolchain目录,否则它将如何找到我的set C编译器作为clang.不过,当我尝试使用cmake –build构建时,它给出了以下错误:
In file included from /builds/meguli/chops/tests/answer_life/answer_life.cpp:2:
/builds/meguli/chops/tests/answer_life/../catch.hpp:644:10: error: no template named ‘is_same_v’ in namespace ‘std’; did you mean ‘is_same’?06001
/usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/type_traits:1517:12: note: ‘is_same’ declared here
struct is_same
^
正如您所看到的,它正在/usr/lib/…/inclue/6.3.0中查看包含文件的主机目录.这不是我想要的,我想为C 17构建,我希望它包含来自clang发行版的标题.我设置SET(仅限CMAKE_FIND_ROOT_PATH_MODE_INCLUDE),以便它在工具链中搜索包含目录,但它不起作用.如何才能在/ opt / clang7下进行搜索?
而不是手动改变CMAKE_CXX_FLAGS(你不应该!)尝试设置cmake使用的C标准:set(CMAKE_CXX_STANDARD 17)
在定义目标之前说出来.
然后,默认情况下,clang默认使用libstdc.要使每个C 17功能可用,只需升级GCC即可.