Ubuntu 18.04 nvcc can't find appropriate host compiler

I’m trying to write some CUDA code, so I installed

$ sudo apt install nvidia-cuda-toolkit

I tried compiling the tutorial https://devblogs.nvidia.com/even-easier-introduction-cuda/, but got this:

$ nvcc add.cu -o add_cuda
ERROR: No supported gcc/g++ host compiler found, but clang-4.0 is available.
       Use 'nvcc -ccbin clang-4.0' to use that instead.

With -v:

$ nvcc add.cu -o add_cuda -v
#$ _SPACE_= 
#$ _CUDART_=cudart
#$ _HERE_=/usr/lib/nvidia-cuda-toolkit/bin
#$ _THERE_=/usr/lib/nvidia-cuda-toolkit/bin
#$ _TARGET_SIZE_=
#$ _TARGET_DIR_=
#$ _TARGET_SIZE_=64
#$ NVVMIR_LIBRARY_DIR=/usr/lib/nvidia-cuda-toolkit/libdevice
#$ PATH=/usr/lib/nvidia-cuda-toolkit/bin:/home/matt/.nvm/versions/node/v10.2.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
#$ LIBRARIES=  -L/usr/lib/x86_64-linux-gnu/stubs
#$ gcc -std=c++14 -D__CUDA_ARCH__=300 -E -x c++  -DCUDA_DOUBLE_MATH_FUNCTIONS -D__CUDACC__ -D__NVCC__  -D"__CUDACC_VER_BUILD__=85" -D"__CUDACC_VER_MINOR__=1" -D"__CUDACC_VER_MAJOR__=9" -include "cuda_runtime.h" -m64 "add.cu" > "/tmp/tmpxft_00001642_00000000-8_add.cpp1.ii" 
ERROR: No supported gcc/g++ host compiler found, but clang-4.0 is available.
       Use 'nvcc -ccbin clang-4.0' to use that instead.
# --error 0x1 --

Now, according to https://docs.nvidia.com/cuda/cuda-installation-guide-linux/#system-requirements, I need at least gcc 7.2.0 or clang 5.0. I seem to meet this:

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.3.0-16ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --with-as=/usr/bin/x86_64-linux-gnu-as --with-ld=/usr/bin/x86_64-linux-gnu-ld --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)

Moreover, using clang caused a linker error:

$ nvcc add.cu -o add_cuda -ccbin clang-4.0
/tmp/tmpxft_000046a5_00000000-10_add.o: In function `main':
/tmp/tmpxft_000046a5_00000000-5_add.cudafe1.cpp:(.text+0x19b): undefined reference to `std::cout'
/tmp/tmpxft_000046a5_00000000-5_add.cudafe1.cpp:(.text+0x1ae): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/tmpxft_000046a5_00000000-5_add.cudafe1.cpp:(.text+0x1bb): undefined reference to `std::ostream::operator<<(float)'
/tmp/tmpxft_000046a5_00000000-5_add.cudafe1.cpp:(.text+0x1c1): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/tmp/tmpxft_000046a5_00000000-5_add.cudafe1.cpp:(.text+0x1cd): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/tmp/tmpxft_000046a5_00000000-10_add.o: In function `__cxx_global_var_init':
/tmp/tmpxft_000046a5_00000000-5_add.cudafe1.cpp:(.text.startup+0x13): undefined reference to `std::ios_base::Init::Init()'
/tmp/tmpxft_000046a5_00000000-5_add.cudafe1.cpp:(.text.startup+0x19): undefined reference to `std::ios_base::Init::~Init()'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

More info:

$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85

Is gcc 7.3.0 bugged? Why is nvcc looking for the wrong clang?

Ubuntu 18.04 is not currently an officially supported environment for CUDA.

https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html

The 7.2.0 you are referring should be considered a maximum supported version for CUDA 9.2