[CMake] Can not get C++ 11 support enabled

Florian Lindner mailinglists at xgm.de
Tue Jul 11 01:07:19 EDT 2017


Hello,

my complete cmake file looks like that:

cmake_minimum_required (VERSION 3.1)
project(Preallocation)
add_executable(prealloc prealloc_parallel.cpp)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_compile_options(-std=c++11)

find_library(petsc petsc
  PATHS $ENV{PETSC_DIR}/$ENV{PETSC_ARCH}/lib)
if(NOT petsc)
  message(FATAL_ERROR "petsc was not found")
endif()
target_link_libraries(prealloc ${petsc})

find_package(Boost 1.60.0
  REQUIRED
  COMPONENTS program_options)
target_link_libraries(prealloc ${Boost_LIBRARIES})

find_package(MPI
  REQUIRED)
target_link_libraries(prealloc ${MPI_LIBRARIES})

set(COMPILE_FLAGS  ${COMPILE_FLAGS} ${MPI_COMPILE_FLAGS})
set(LINK_FLAGS ${LINK_FLAGS} ${MPI_LINK_FLAGS})

but still, cmake refused to enable c++11 support, make VERBOSE=1 shows

[ 50%] Building CXX object CMakeFiles/prealloc.dir/prealloc_parallel.cpp.o
/usr/bin/c++     -O3 -DNDEBUG   -o CMakeFiles/prealloc.dir/prealloc_parallel.cpp.o -c
/data/scratch/lindnefn/petsc_prealloc/prealloc_parallel.cpp
In file included from /usr/include/c++/5/random:35:0,
                 from /data/scratch/lindnefn/petsc_prealloc/prealloc_parallel.cpp:4:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #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 \
  ^
In file included from /data/scratch/lindnefn/software/petsc/include/petscis.h:7:0,
                 from /data/scratch/lindnefn/software/petsc/include/petscvec.h:9,
                 from /data/scratch/lindnefn/software/petsc/include/petscmat.h:6,
                 from /data/scratch/lindnefn/petsc_prealloc/prealloc_parallel.cpp:7:
/data/scratch/lindnefn/software/petsc/include/petscsys.h:130:17: fatal error: mpi.h: No such file or directory
compilation terminated.

What is wrong here+

cmake 3.5.1

Thanks,
Florian


More information about the CMake mailing list