torch / torch7

http://torch.ch
Other
9k stars 2.38k forks source link

Installation error: identifier "nullptr" is undefined #682

Open allencch opened 8 years ago

allencch commented 8 years ago

I am using Arch Linux and following the installation guide, then I get these errors

[  7%] Building NVCC (Device) object lib/THC/CMakeFiles/THC.dir/THC_generated_THCReduceApplyUtils.cu.o
[  7%] Building NVCC (Device) object lib/THC/CMakeFiles/THC.dir/THC_generated_THCHalf.cu.o
[  7%] Building NVCC (Device) object lib/THC/CMakeFiles/THC.dir/THC_generated_THCBlas.cu.o
[ 10%] Building NVCC (Device) object lib/THC/CMakeFiles/THC.dir/THC_generated_THCStorage.cu.o
/usr/lib/gcc/x86_64-pc-linux-gnu/6.1.1/include/stddef.h(436): error: identifier "nullptr" is undefined
...

I tried adding

list(APPEND CUDA_NVCC_FLAGS "-arch=sm_20;-std=c++11;-O2;-DVERBOSE")
SET(CUDA_PROPAGATE_HOST_FLAGS OFF)

as this post, to extra/cunnx/CMakeLists.txt, extra/cutorch/lib/THC/CMakeLists.txt, and extra/cunn/lib/THCUNN/CMakeLists.txt, but it doesn't solve the problem. Is there any solution on this?

iamalbert commented 8 years ago

your gcc version is too high, try gcc 4.6 or 4.9

allencch commented 8 years ago

@iamalbert

Thank you. I installed 4.9 and use the GCC 4.9 to compile. Most of the compilations work fine, but only cunnx has the error which uses version 6.1 instead.

-- The C compiler identification is GNU 4.9.3
-- The CXX compiler identification is GNU 4.9.3
-- Check for working C compiler: /usr/bin/gcc-4.9
-- Check for working C compiler: /usr/bin/gcc-4.9 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/g++-4.9
-- Check for working CXX compiler: /usr/bin/g++-4.9 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Torch7 in /home/user/torch/install
-- Found CUDA: /opt/cuda (Required is at least version "4.0") 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/torch/extra/cunnx/build
[ 50%] Building NVCC (Device) object CMakeFiles/cunnx.dir/cunnx_generated_init.cu.o
CMake Warning (dev) at cunnx_generated_init.cu.o.cmake:129 (if):
  Policy CMP0054 is not set: Only interpret if() arguments as variables or
  keywords when unquoted.  Run "cmake --help-policy CMP0054" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.

  Quoted keywords like "COMMAND" will no longer be interpreted as keywords
  when the policy is set to NEW.  Since the policy is not set the OLD
  behavior will be used.
Call Stack (most recent call first):
  cunnx_generated_init.cu.o.cmake:156 (cuda_execute_process)

This warning is for project developers.  Use -Wno-dev to suppress it.

/usr/lib/gcc/x86_64-pc-linux-gnu/6.1.1/include/stddef.h(436): error: identifier "nullptr" is undefined

Is there anyway to proceed without uninstall gcc 6.1?

harshhemani commented 8 years ago

Faced a similar issue with theano. Solved it by adding flags to nvcc when compiling. See here and here

tmathmeyer commented 8 years ago

how did you add those flags to nvcc?

harshhemani commented 8 years ago

Theano call the nvcc from within python code, I passed the flags at the relevant place (see link above). Since theano also accepts nvcc flags as part of THEANO_FLAGS environment variable, we don't need to change the code. I just changed my environment variable (see here) and theano was able to use nvcc using those flags.

aep commented 8 years ago

cuda is broken with gcc6, just use clang for nvcc.

i can't figure out the cmake cancer, so here's my hack for torch:

cat /opt/cuda/bin/nvcc
#!/bin/sh
echo "$@" >&2
args="$(echo "$@" | sed -e 's;-ccbin [^ ]* ;;') -ccbin /sbin/clang++"
/opt/cuda/bin/nvcc_ $args

maybe @allencch could invoke the cmake rituals to do that?

synchro-- commented 8 years ago

@harshhemani

I'm on Arch Linux too. I have installed torch (i.e. I have the TREPL but not the whole setup, for instance no tab completion, etc. ) but if I try to run install.sh in the torch folder (as depicted on the website getting started page) I keep getting the same error though, whether I set my CC and CXX variables to gcc4.9 or clang. It is always the same:


`
and from there all the others as you know. Any suggestion? 
The script was made with an old version of gcc in mind. Now, there must be the --std=c11 missing somewhere. Where should I put it?
jgoenetxea commented 7 years ago

This is the same answer posted by @aep but described step by step for Ubuntu 17.04. Thanks @aep for your answer.

1- Install clang (try with clang-3.8 as suggested by @eternalthinker): $ sudo apt-get install clang

2- Find your 'nvcc' file location (in my case was '/usr/local/cuda-8.0/bin/nvcc'): $ locate nvcc

3- The 'nvcc' file is a binary file, so first change the name adding a '' in the back: `$ sudo mv /usr/local/cuda-8.0/bin/nvcc /usr/local/cuda-8.0/bin/nvcc`

4- Generate a text file (bash script) using your favorite text editor and paste the code:

#!/bin/sh
echo "$@" >&2
args="$(echo "$@" | sed -e 's;-ccbin [^ ]* ;;') -ccbin /usr/bin/clang++"
/usr/local/cuda-8.0/bin/nvcc_ $args

(Note that the only difference between this code and that posted by @aep are the paths)

5- Run the torch installer (in the correct location): $ ./install.sh

eternalthinker commented 7 years ago

@jgoenetxea Version 4.0 of clang was throwing errors. Worked with clang-3.8

jgoenetxea commented 7 years ago

@eternalthinker Ok, I have updated the answer. I was able to compile it with clang 4.0 (the 'nullptr' error was fixed), but yes, there could be errors later. Thank you very much.