【发布时间】:2017-11-09 23:28:29
【问题描述】:
我正在使用 cmake 构建一个项目,该项目使用 Google 的密集哈希映射。我需要检查相应的头文件是否存在。因此我添加了
set (CMAKE_CXX_STANDARD 11)
INCLUDE (CheckIncludeFileCXX)
CHECK_INCLUDE_FILE_CXX("sparsehash/dense_hash_map" HAVE_SPARSEHASH)
致我的CMakeLists.txt。但是,我编译时找不到标头
在一些旧的编译器上。问题是头文件必须在
C++11 和这些编译器默认不是 C++11:
/usr/bin/clang++ -o CMakeFiles/cmTC_4186d.dir/CheckIncludeFile.cxx.o -c /home/florent/src/IVMPG/HPCombi/build/CMakeFiles/CMakeTmp/CheckIncludeFile.cxx
In file included from /home/florent/src/IVMPG/HPCombi/build/CMakeFiles/CMakeTmp/CheckIncludeFile.cxx:1:
In file included from /usr/local/include/sparsehash/dense_hash_map:102:
In file included from /usr/bin/../lib64/gcc/x86_64-suse-linux/7/../../../../include/c++/7/type_traits:35:
/usr/bin/../lib64/gcc/x86_64-suse-linux/7/../../../../include/c++/7/bits/c++0x_warning.h:32:2: error: This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support \
^
因此 CMake 认为该文件不存在。
所以问题是:我如何确保我使用的是c++11(甚至是c++14)
当我测试一些包含或符号时?
【问题讨论】: