Conda CMAKE CXX Compiler error while compiling Pytorch

0

I was following How to build PyTorch from Source in order to install Pytorch as I have older Graphic card which only supports Cuda 11.4. I am working in Conda environment. At the last stage I am getting following error.


Building wheel torch-2.4.0a0+git2b1ba0c
-- Building version 2.4.0a0+git2b1ba0c
cmake -GNinja -DBUILD_PYTHON=True -DBUILD_TEST=True -DCMAKE_ARGS=-DCMAKE_AR=/home/sinfinities/.conda/envs/StableD/bin/x86_64-conda-linux-gnu-ar -DCMAKE_CXX_COMPILER_AR=/home/sinfinities/.conda/envs/StableD/bin/x86_64-conda-linux-gnu-gcc-ar -DCMAKE_C_COMPILER_AR=/home/sinfinities/.conda/envs/StableD/bin/x86_64-conda-linux-gnu-gcc-ar -DCMAKE_RANLIB=/home/sinfinities/.conda/envs/StableD/bin/x86_64-conda-linux-gnu-ranlib -DCMAKE_CXX_COMPILER_RANLIB=/home/sinfinities/.conda/envs/StableD/bin/x86_64-conda-linux-gnu-gcc-ranlib -DCMAKE_C_COMPILER_RANLIB=/home/sinfinities/.conda/envs/StableD/bin/x86_64-conda-linux-gnu-gcc-ranlib -DCMAKE_LINKER=/home/sinfinities/.conda/envs/StableD/bin/x86_64-conda-linux-gnu-ld -DCMAKE_STRIP=/home/sinfinities/.conda/envs/StableD/bin/x86_64-conda-linux-gnu-strip -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/sinfinities/Downloads/pytorch/torch -DCMAKE_PREFIX_PATH=/home/sinfinities/.conda/envs/StableD/lib/python3.12/site-packages;/home/sinfinities/.conda/envs/StableD:/home/sinfinities/.conda/envs/StableD/x86_64-conda-linux-gnu/sysroot/usr -DNUMPY_INCLUDE_DIR=/home/sinfinities/.conda/envs/StableD/lib/python3.12/site-packages/numpy/core/include -DPYTHON_EXECUTABLE=/home/sinfinities/.conda/envs/StableD/bin/python -DPYTHON_INCLUDE_DIR=/home/sinfinities/.conda/envs/StableD/include/python3.12 -DPYTHON_LIBRARY=/home/sinfinities/.conda/envs/StableD/lib/libpython3.12.a -DTORCH_BUILD_VERSION=2.4.0a0+git2b1ba0c -DUSE_NUMPY=True /home/sinfinities/Downloads/pytorch
-- The CXX compiler identification is GNU 9.5.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: /home/sinfinities/.conda/envs/StableD/bin/c++
-- Check for working CXX compiler: /home/sinfinities/.conda/envs/StableD/bin/c++ - broken
CMake Error at /home/sinfinities/.conda/envs/StableD/share/cmake-3.26/Modules/CMakeTestCXXCompiler.cmake:60 (message):
  The C++ compiler

    "/home/sinfinities/.conda/envs/StableD/bin/c++"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/sinfinities/Downloads/pytorch/build/CMakeFiles/CMakeScratch/TryCompile-tQ7Kro
    
    Run Build Command(s):/home/sinfinities/.conda/envs/StableD/bin/ninja -v cmTC_6d41d && [1/2] /home/sinfinities/.conda/envs/StableD/bin/c++    -o CMakeFiles/cmTC_6d41d.dir/testCXXCompiler.cxx.o -c /home/sinfinities/Downloads/pytorch/build/CMakeFiles/CMakeScratch/TryCompile-tQ7Kro/testCXXCompiler.cxx
    [2/2] : && /home/sinfinities/.conda/envs/StableD/bin/c++   CMakeFiles/cmTC_6d41d.dir/testCXXCompiler.cxx.o -o cmTC_6d41d   && :
    FAILED: cmTC_6d41d 
    : && /home/sinfinities/.conda/envs/StableD/bin/c++   CMakeFiles/cmTC_6d41d.dir/testCXXCompiler.cxx.o -o cmTC_6d41d   && :
    /home/sinfinities/.conda/envs/StableD/bin/../lib/gcc/x86_64-conda-linux-gnu/9.5.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/sinfinities/.conda/envs/StableD/bin/../lib/gcc/x86_64-conda-linux-gnu/9.5.0/libstdc++.so: undefined reference to `memcpy@GLIBC_2.14'
    /home/sinfinities/.conda/envs/StableD/bin/../lib/gcc/x86_64-conda-linux-gnu/9.5.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/sinfinities/.conda/envs/StableD/bin/../lib/gcc/x86_64-conda-linux-gnu/9.5.0/libstdc++.so: undefined reference to `aligned_alloc@GLIBC_2.16'
    /home/sinfinities/.conda/envs/StableD/bin/../lib/gcc/x86_64-conda-linux-gnu/9.5.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/sinfinities/.conda/envs/StableD/bin/../lib/gcc/x86_64-conda-linux-gnu/9.5.0/libstdc++.so: undefined reference to `clock_gettime@GLIBC_2.17'
    collect2: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:29 (project)

My nvidia-smi output is

Sun Mar 31 22:59:04 2024       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.223.02   Driver Version: 470.223.02   CUDA Version: 11.4     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  Off  | 00000000:01:00.0 N/A |                  N/A |
| 33%   43C    P8    N/A /  N/A |     53MiB /  1999MiB |     N/A      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

nvcc --version

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Wed_Jun__2_19:15:15_PDT_2021
Cuda compilation tools, release 11.4, V11.4.48
Build cuda_11.4.r11.4/compiler.30033411_0

gcc --version

gcc (conda-forge gcc 9.5.0-17) 9.5.0
Copyright (C) 2019 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.

c++ --version

c++ (conda-forge gcc 9.5.0-17) 9.5.0
Copyright (C) 2019 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 have been going back and forth with this but not able to figure out how to fix it. Any guidance will be much appreciated.