成員編譯我的程序與CMake的:「sqrtf」不是「性病」
$ 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})
問題出現在您的'CMakeLists.txt'文件或您的C++代碼中。你還沒有顯示,所以我們無法幫助。 – Angew
爲什麼使用'sqrtf'或'floorf'?特別是對於C++ 11,'sqrt'能夠直接處理'float'。 – oLen
@Angew添加CMakeLists.txt oLen:您的評論已解決此問題。用floor和sqrt替換floorf和sqrtf的所有實例都可以消除錯誤。不知道爲什麼。 – Mossmyr