Mossmyr
Mossmyr

Reputation: 989

CMake: ‘sqrtf’ is not a member of ‘std’

After compiling my program with

$ cmake .
$ make

I get 5 errors of this form:

$ make
Scanning dependencies of target Project
[ 50%] Building CXX object CMakeFiles/myproj.dir/main.cpp.o
In file included from /path/to/my/proj/main.cpp:2:0: 
/path/to/my/proj/library.hpp: In member function ‘virtual double MyProjClass::get_value(double, double) const’:
/path/to/my/proj/library.hpp:419:26: error: ‘sqrtf’ is not a member of ‘std’
     const float F = (std::sqrtf(1.0f + 2.0f) - 1.0f) / 2;
                      ^

Other errors include floorf not being a member of std.

Looking at this thread, it's because I'm not compiling with C++11, and looking at this thread thread, "[...] CMake will make sure the C++ compiler is invoked with the appropriate command line flags."

Well, my CMake is obviously not doing this. Why am I getting these errors, and how do I go about fixing them?

Edit: Here's my CMakeLists.txt

cmake_minimum_required(VERSION 3.5)
project(Noise)

set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES main.cpp vector.hpp noise.hpp)
add_executable(Noise ${SOURCE_FILES})

find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})
target_link_libraries(Noise ${SDL2_LIBRARIES})

Upvotes: 3

Views: 5747

Answers (1)

Mike Kinghan
Mike Kinghan

Reputation: 61540

You don't say what C++ compiler you are using but assuming it is g++ 5.x though 7, sqrtf and floorf are not within the std namespace under -std=c++11, -std=c++14 or -std=c++1z. They are simply in the global namespace, when cmath is included.

Upvotes: 8

Related Questions