Error when compiling with CMake on Linux

Hi all,

I want to use Libtorch on Linux (Ubuntu 22.04). I have managed to install CUDA 11.3, CMake, and GCC-10, but when I go to build the example project using “sudo cmake .”, I get the following error:

-- The CUDA compiler identification is unknown
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - failed
-- Check for working CUDA compiler: /usr/local/cuda
-- Check for working CUDA compiler: /usr/local/cuda - broken
CMake Error at /usr/share/cmake-3.22/Modules/CMakeTestCUDACompiler.cmake:56 (message):
  The CUDA compiler


  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/joy/Downloads/HelloTRT/CMakeFiles/CMakeTmp
    Run Build Command(s):/usr/bin/gmake -f Makefile cmTC_8fa0e/fast && /usr/bin/gmake  -f CMakeFiles/cmTC_8fa0e.dir/build.make CMakeFiles/cmTC_8fa0e.dir/build
    gmake[1]: Entering directory '/home/joy/Downloads/HelloTRT/CMakeFiles/CMakeTmp'
    Building CUDA object CMakeFiles/cmTC_8fa0e.dir/
    /usr/local/cuda      -c /home/joy/Downloads/HelloTRT/CMakeFiles/CMakeTmp/ -o CMakeFiles/cmTC_8fa0e.dir/
    gmake[1]: /usr/local/cuda: Permission denied
    gmake[1]: *** [CMakeFiles/cmTC_8fa0e.dir/build.make:78: CMakeFiles/cmTC_8fa0e.dir/] Error 127
    gmake[1]: Leaving directory '/home/joy/Downloads/HelloTRT/CMakeFiles/CMakeTmp'
    gmake: *** [Makefile:127: cmTC_8fa0e/fast] Error 2

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  /media/joy/16A851D7A851B649/linux/libtorch-cxx11-abi-shared-with-deps-1.11.0+cu113/libtorch/share/cmake/Caffe2/public/cuda.cmake:41 (enable_language)
  /media/joy/16A851D7A851B649/linux/libtorch-cxx11-abi-shared-with-deps-1.11.0+cu113/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:88 (include)
  /media/joy/16A851D7A851B649/linux/libtorch-cxx11-abi-shared-with-deps-1.11.0+cu113/libtorch/share/cmake/Torch/TorchConfig.cmake:68 (find_package)
  CMakeLists.txt:7 (find_package)

-- Configuring incomplete, errors occurred!
See also "/home/joy/Downloads/HelloTRT/CMakeFiles/CMakeOutput.log".
See also "/home/joy/Downloads/HelloTRT/CMakeFiles/CMakeError.log".

Since I have limited space on the Ubuntu drive, I created a softlink from /usr/local/cuda to the CUDA toolkit installation directory on another drive. I have tried setting the permissions for “Others” to be able to do everything to this folder and its contents, and have tried running cmake with “sudo”, but I still get this “Permission denied” error.

Any help would be greatly appreciated.


Check the permission of the sym link and the original file via ls -la and either add the current user to it or specify the original CUDA install dir via CUDA_HOME=...

Thanks for your quick reply. ls -la returned lrwxrwxrwx 1 root root 42 jun 1 16:01 cuda -> /media/joy/16A851D7A851B649/linux/toolkit/ for the sym link, I’m not quite sure if that means the current user is already added or not.

I tried specifying the original CUDA install dir with set(CUDA_HOME "/media/joy/16A851D7A851B649/linux/toolkit") in CMakeLists.txt, but then I get No CMAKE_CUDA_COMPILER could be found.

If I specify the original CUDA install dir with set(CMAKE_CUDA_COMPILER "/media/joy/16A851D7A851B649/linux/toolkit") instead, then it does seem to find it, but again gives the “Permission denied” error from the original post.

I’m getting pretty close to just buying a larger USB drive and re-installing Ubuntu so I can put CUDA in the default directory, but hopefully I can find a simpler solution.