Error when compiling with CMake on Linux

username: jonahclarsen
cooked: <p>Hi all,</p>
<p>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:</p>
<pre><code class="lang-auto">-- 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

    "/usr/local/cuda"

  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 &amp;&amp; /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/main.cu.o
    /usr/local/cuda      -c /home/joy/Downloads/HelloTRT/CMakeFiles/CMakeTmp/main.cu -o CMakeFiles/cmTC_8fa0e.dir/main.cu.o
    gmake[1]: /usr/local/cuda: Permission denied
    gmake[1]: *** [CMakeFiles/cmTC_8fa0e.dir/build.make:78: CMakeFiles/cmTC_8fa0e.dir/main.cu.o] 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".
</code></pre>
<p>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.</p>
<p>Any help would be greatly appreciated.</p>
<p>Thanks!<br>
Jonah</p>

username: ptrblck
cooked: <p>Check the permission of the sym link and the original file via <code>ls -la</code> and either add the current user to it or specify the original CUDA install dir via <code>CUDA_HOME=...</code></p>

username: jonahclarsen
cooked: <p>Thanks for your quick reply. <code>ls -la</code> returned <code>lrwxrwxrwx  1 root root   42 jun  1 16:01 cuda -&gt; /media/joy/16A851D7A851B649/linux/toolkit/</code> for the sym link, I’m not quite sure if that means the current user is already added or not.</p>
<p>I tried specifying the original CUDA install dir with <code>set(CUDA_HOME "/media/joy/16A851D7A851B649/linux/toolkit")</code> in CMakeLists.txt, but then I get <code>No CMAKE_CUDA_COMPILER could be found.</code></p>
<p>If I specify the original CUDA install dir with <code>set(CMAKE_CUDA_COMPILER "/media/joy/16A851D7A851B649/linux/toolkit")</code> instead, then it does seem to find it, but again gives the “Permission denied” error from the original post.</p>
<p>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.</p>