Can not get C++ 11 support enabled

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Can not get C++ 11 support enabled

Florian Lindner
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
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can not get C++ 11 support enabled

Michael Ellery

> On Jul 10, 2017, at 10:07 PM, Florian Lindner <[hidden email]> wrote:
>
> 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})
>

I would try moving the add_executable() to the end of the CMakeLists file (after the set() and find_library calls…)

-Mike

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can not get C++ 11 support enabled

Craig Scott-3
As well as moving the add_executable() call after you set the various CMAKE_CXX... variables, you should also replace the call to add_compile_options(-std=c++11) with the following:

set(CMAKE_CXX_EXTENSIONS OFF)


On Tue, Jul 11, 2017 at 3:11 PM, Michael Ellery <[hidden email]> wrote:

> On Jul 10, 2017, at 10:07 PM, Florian Lindner <[hidden email]> wrote:
>
> 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})
>

I would try moving the add_executable() to the end of the CMakeLists file (after the set() and find_library calls…)

-Mike

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake



--
Craig Scott
Melbourne, Australia

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can not get C++ 11 support enabled

Petr Kmoch
As others have suggested, moving the add_executable() after the set() calls is the correct solution.

The reason is that variables like CMAKE_CXX_STANDARD are used to pre-initialise a target's properties when the target is created. In other words, at the time add_executable() is called, CMake will inspect variables like CMAKE_CXX_STANDARD and use them to initialise the target's properties like CXX_STANDARD. It's the properties which really control the target's build. See https://cmake.org/cmake/help/latest/variable/CMAKE_CXX_STANDARD.html and https://cmake.org/cmake/help/latest/prop_tgt/CXX_STANDARD.html for details.

The same applies to add_compile_options(). From its docs ( https://cmake.org/cmake/help/latest/command/add_compile_options.html ): "Adds options to the compiler command line for targets in the current directory and below that are added after this command is invoked"

But Craig is right that you shouldn't add `-std` directly, but use CXX_STANDARD and CXX_EXTENSIONS instead.

Petr

On 11 July 2017 at 07:21, Craig Scott <[hidden email]> wrote:
As well as moving the add_executable() call after you set the various CMAKE_CXX... variables, you should also replace the call to add_compile_options(-std=c++11) with the following:

set(CMAKE_CXX_EXTENSIONS OFF)


On Tue, Jul 11, 2017 at 3:11 PM, Michael Ellery <[hidden email]> wrote:

> On Jul 10, 2017, at 10:07 PM, Florian Lindner <[hidden email]> wrote:
>
> 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})
>

I would try moving the add_executable() to the end of the CMakeLists file (after the set() and find_library calls…)


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Loading...