Unable to declare to use C++11 in CLion - c++11

For hours I'm trying to declare to use C++11 in CLion without any effects. Still CLion shows me undefined functions name that actually exist, but in C++11:
.
My CMakeLists.txt files looks like:
cmake_minimum_required(VERSION 3.6)
project(Program)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread")
add_executable(program src/program.cpp)
How am I doing wrong?

Related

How to debug in Clion using Cmake if project needs libraries

I'm new in C. My code uses termcap library. And I'm trying to debug my code using Clion through Cmake Application. But it can't be compiled because functions that i use from a library are undefined. What should i add to CMakeLists.txt to debug my project?
My CMakeLists.txt now:
cmake_minimum_required(VERSION 3.21)
project(minishell C)
set(CMAKE_C_STANDARD 99)
add_executable(minishell main.c)
When i compile using clang i just do this:
clang main.c -ltermcap
and it works.
Can't understand what to do. Please help.

std::uint32_t is not a type in c++11

I am using std::uint32_t as a type in c++11 on a cmake project.
I added set_property(cxx_compiler_flag "-std=c++11" in CMakeLists but the error is still here.
If you want to use c++11 you can write:
set(CMAKE_CXX_STANDARD 11)
CMAKE_CXX_STANDARD in cmake
Use case:
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
project(EventBusDev)
set(CMAKE_CXX_STANDARD 14)
Live Example
Also please remember to include <cstdint>

How to set compiler standard in CMake

I want to use a timer as advised in
How can I measure the execution time of one thread?
However, I receive the error message
In file included from /usr/include/c++/5/thread:35:0,
/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 \
^
The CMake output of
message("${CMAKE_CXX_FLAGS}" and "${CMAKE_C_FLAGS}")
is
-std=c++11 -fPIC -Wall;and; -std=c++11
What is wrong?
If you would like your project to require C++11, I suggest you do something like this:
cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
project(test)
[...]
If you are building a library, and you would like user of your library to transitively use the correct flags, you could look into https://cmake.org/cmake/help/latest/manual/cmake-compile-features.7.html#requiring-language-standards

How to create a makefile for Keystone library using cmake? [duplicate]

Work on Ubuntu 16
I used g++ main.cpp -lpq command for compiler my small project. Now I use Clion and wanna do same what I do with g++. But I can't add compiler flags in cmake file and get compile error.
cmake_minimum_required(VERSION 3.5.1)
project(day_g)
set(CMAKE_CXX_FLAGS "-lpq")
add_definitions(-lpq)
message("CMAKE_CXX_FLAGS is ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(day_g ${SOURCE_FILES})
Also I run only cmake file and get CMAKE_CXX_FLAGS with -lpq flag.
CMAKE_CXX_FLAGS is -lpq
-- Configuring done
-- Generating done
How properly add compiler flags to cmake file?
Flag -l is for linker, not for compiler. This flag is used for link with libraries. CMake has special command target_link_libraries for that purpose:
target_link_libraries(day_g pq)
-lq is not a compiler flag (CFLAGS) but a linker flag.
To pass a library in a CMake project you should use:
target_link_libraries(target_name libraries...)
Note that if you specify 'q' as library the project will link with libq.a or, if you are on windows q.dll.
... in your CMakeLists.txt the correct line to add is:
target_link_libraries(day_g pq)
Note also that when you add a CFLAG you should also "remember" the previous ones that may be added by libraries or by your platform, ie:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
To check the exact flags cmake is passing to compiler or linker you can always run, from the build directory, the following command:
make VERBOSE=1

Triggering C++11 support in NVCC with CMake

I'm running Ubuntu 15.10 with CUDA 7.5. CMmake is v3.2.2, NVCC is release 7.5, v7.5.17; GCC is Ubuntu 5.2.1-22ubuntu2 v5.2.1
Triggering C++11 in regular projects is easy with:
project(foo CXX)
set(TARGET foo CMAKE_CXX_STANDARD 11)
I'm defining my CUDA project with:
find_package(CUDA REQUIRED)
CUDA_ADD_EXECUTABLE(foo ${foo_src} ${foo_hdr} ${foo_cu})
But the C++11 support doesn't get propagated to NVCC. I have to add:
list(APPEND CUDA_NVCC_FLAGS "-std=c++11")
This seems like a kludge. There was evidently work on this recently according to this task, but I haven't been able to find the results.
How do I get CMake to automatically set the C++11 flags when declaring the project as C++11?
EDIT: I've retuned to to this question with CUDA 8.0 and CMake 3.5.1.
From the documentation, set(CUDA_PROPAGATE_HOST_FLAGS ON) will propagate the contents of CMAKE_CXX_FLAGS, so the following triggers C++11 for both cpp and nvcc:
set (CMAKE_CXX_FLAGS "--std=c++11")
set (CUDA_PROPAGATE_HOST_FLAGS ON)
However, set(CMAKE_CXX_STANDARD 11) does not impact CMAKE_CXX_FLAGS, so the following gives compiler errors for C++11 device code, as there's nothing to propagate:
set (CMAKE_CXX_STANDARD 11)
set (CUDA_PROPAGATE_HOST_FLAGS ON)
I can't seem to find a combination of CMake commands that avoids explicitly setting --std=c++11 in either CXX or CUDA flags.
Since CMake 3.8 (since CMake supports CUDA as a language) there is a new target property CUDA_STANDARD. Although its name is quite confusing, it adds the -std=XXX to the nvcc compile command.
With a recent CMake version the proper way would be
cmake_minimum_required(VERSION 3.8.2)
enable_language(CUDA)
add_executable(foo ${foo_src} ${foo_cu})
set_property(TARGET foo PROPERTY CUDA_STANDARD 11)

Resources