gpt4 book ai didi

c++11 - CMake: ‘sqrtf’ 不是 ‘std’ 的成员

转载 作者:行者123 更新时间:2023-12-04 01:46:41 33 4
gpt4 key购买 nike

编译我的程序后

$ cmake .
$ make

我收到 5 个这种形式的错误:

$ 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;
^

其他错误包括 floorf 不是 std 的成员。

查看this thread ,这是因为我没有使用 C++11 进行编译,而是查看 this thread线程,“[...] CMake 将确保使用适当的命令行标志调用 C++ 编译器。”

好吧,我的 CMake 显然不是这样做的。为什么会出现这些错误,我该如何修复它们?

编辑:这是我的 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})

最佳答案

你没有说你使用的是什么 C++ 编译器,但假设它是 g++ 5.x though 7,sqrtffloorf 不在 -std=c++11-std=c++14 std 命名空间内 或 -std=c++1z。他们是仅在全局命名空间中,当包含 cmath 时。

关于c++11 - CMake: ‘sqrtf’ 不是 ‘std’ 的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43183252/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com