1

I'm trying to compile my program with nvcc and g++-5 and I get this error.

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;

Using g++ it compiles correctly, but nvcc required g++-5. Does anyone know how to solve this? By the way, this started happening once I ran sudo do-release-upgrade on Ubuntu.

nvcc --version output is this:

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 output is this:

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 output is this:

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.

I'm compiling with c++11 and cmath is not included in my source files. This is my CMakeLists.txt.

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)
talonmies
  • 70,661
  • 34
  • 192
  • 269
Michael
  • 1,018
  • 4
  • 14
  • 30

3 Answers3

2

You need to make nvcc to run host C++ compiler in C++11 mode (passing this option to gcc directly is not enough):

 nvcc -Xcompiler "-std=c++11"

details can be found here

Related information:

c++ version supported by cuda 5.0

Error while using CUDA and C++11

Slava
  • 43,454
  • 1
  • 47
  • 90
  • I tried that, not working. Also tried this ``nvcc -std=c++11 src/*.cpp -o main -lpthread -lGL -lGLEW``. – Michael Nov 30 '17 at 13:53
  • Enable verbose mode in cmake an check what parameters are passed to nvcc – Slava Nov 30 '17 at 13:57
  • You may also want to enable verbose mode for `nvcc` itself to check how it calls g++. – Slava Nov 30 '17 at 14:05
  • Seems like it fails compiling before calling nvcc. The command called before the error pops up is ``/usr/bin/g++-5 -DGLFW_DLL -I/home/dev/work/octree-cpu-pcd/src -std=c++11 -o CMakeFiles/cpu_pcd.dir/src/controls.cpp.o -c /home/dev/work/octree-cpu-pcd/src/controls.cpp`` – Michael Nov 30 '17 at 14:05
  • Check version of `/usr/bin/gcc-5` and try to compile simple program with `std::isnan` with it directly. You need to fix that and that is unrelated to nvcc and CUDA. – Slava Nov 30 '17 at 14:07
  • Changed it to compile with g++-5 btw. – Michael Nov 30 '17 at 14:08
  • ok, with g++ it compiles correctly. But nvcc supports only g++-5, any suggestion? – Michael Nov 30 '17 at 14:11
  • 2
    "any suggestion?" fix g++-5 – Slava Nov 30 '17 at 14:15
1

std::isnan and std::isinf declared in <cmath> starting with C++11. Is that header included? Is the compile done in C++11 or later mode?

Eljay
  • 4,648
  • 3
  • 16
  • 27
1

For those interested I solved it changing two lines of CMakeLists.txt like this:

set(CMAKE_C_COMPILER /usr/bin/gcc-5 CACHE PATH "" FORCE)
set(CMAKE_CXX_COMPILER /usr/bin/g++ CACHE PATH "" FORCE)

Now it compiles correctly, thanks to all willing to help.

Michael
  • 1,018
  • 4
  • 14
  • 30