首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >std::isnan没有被声明,有g++-5

std::isnan没有被声明,有g++-5
EN

Stack Overflow用户
提问于 2017-11-30 13:31:49
回答 3查看 2.5K关注 0票数 1

我试图编译我的程序与nvcc和g++-5,我得到了这个错误。

代码语言:javascript
复制
In file included from /usr/include/glm/detail/func_common.hpp:426:0,
             from /usr/include/glm/detail/func_geometric.inl:5,
             from /usr/include/glm/detail/func_geometric.hpp:113,
             from /usr/include/glm/geometric.hpp:6,
             from /usr/include/glm/detail/func_matrix.inl:4,
             from /usr/include/glm/detail/func_matrix.hpp:149,
             from /usr/include/glm/detail/type_mat2x2.inl:4,
             from /usr/include/glm/detail/type_mat2x2.hpp:182,
             from /usr/include/glm/mat2x2.hpp:6,
             from /usr/include/glm/glm.hpp:71,
             from src/controls.cpp:6:
/usr/include/glm/detail/func_common.inl:623:14: error: ‘std::isnan’   has not been declared
   using std::isnan;
          ^
/usr/include/glm/detail/func_common.inl:659:14: error: ‘std::isinf’ has not been declared
   using std::isinf;

使用g++可以正确编译,但nvcc需要g++-5.有人知道怎么解决这个问题吗?顺便说一句,当我在Ubuntu上运行sudo do-release-upgrade时,这种情况就开始发生了。

nvcc --version输出如下:

代码语言:javascript
复制
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Tue_Jan_10_13:22:03_CST_2017
Cuda compilation tools, release 8.0, V8.0.61

g++-5 --version输出如下:

代码语言:javascript
复制
g++-5 (Ubuntu 5.5.0-1ubuntu1) 5.4.1 20171010
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

g++ --version输出如下:

代码语言:javascript
复制
g++ (Ubuntu 7.2.0-8ubuntu3) 7.2.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

我正在用c++11进行编译,我的源文件中没有包含c计量。这是我的CMakeLists.txt

代码语言:javascript
复制
cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
set(CMAKE_C_COMPILER /usr/bin/gcc-5 CACHE PATH "" FORCE)
set(CMAKE_CXX_COMPILER /usr/bin/gcc-5 CACHE PATH "" FORCE)
project(cpu_pcd C CXX CUDA)

add_compile_options(-std=c++11)

file(GLOB SRC src/*.cpp src/*.hpp)

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)

find_package(OpenGL REQUIRED)
find_package(glfw3 REQUIRED)
find_package(GLEW REQUIRED)
find_package(CUDA REQUIRED)

include_directories(src/)
include_directories(${OPENGL_INCLUDE_DIRS})
include_directories(${GLFW_INCLUDE_DIRS})
include_directories(${CUDA_INCLUDE_DIRS})

cuda_add_library(kernel src/update_particles.cu)
cuda_add_executable(cpu_pcd ${SRC})

set_target_properties(cpu_pcd
  PROPERTIES CUDA_SEPARABLE_COMPILATION on)

target_link_libraries(cpu_pcd kernel)
target_link_libraries(cpu_pcd ${OPENGL_LIBRARIES} glfw  ${GLEW_LIBRARIES} ${CUDA_LIBRARIES} pthread)
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-11-30 19:43:19

对于那些感兴趣的人,我解决了它,修改了两行CMakeLists.txt,如下所示:

代码语言:javascript
复制
set(CMAKE_C_COMPILER /usr/bin/gcc-5 CACHE PATH "" FORCE)
set(CMAKE_CXX_COMPILER /usr/bin/g++ CACHE PATH "" FORCE)

现在,由于大家都愿意帮忙,它的编译是正确的。

票数 1
EN

Stack Overflow用户

发布于 2017-11-30 13:46:08

您需要让nvccC++11模式运行主机C++编译器(直接将此选项传递给gcc是不够的):

代码语言:javascript
复制
 nvcc -Xcompiler "-std=c++11"

详细信息可以找到这里

有关资料:

CODA5.0支持的c++版本

使用CUDA和C++11时出错

票数 2
EN

Stack Overflow用户

发布于 2017-11-30 13:38:07

std::isnan和std::isinf在<cmath>中声明,以C++11开头。包含标头吗?编译是以C++11或更高模式完成的吗?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47574698

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档