向各位 Linux/Ubuntu 爱好者问好,
我正在尝试在 Ubuntu 21.10 上运行 Kinect 2。我逐一发出的命令如下:
marietto-BHYVE:/home/marietto# nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Mon_May__3_19:15:13_PDT_2021
Cuda compilation tools, release 11.3, V11.3.109
Build cuda_11.3.r11.3/compiler.29920130_0
marietto-BHYVE:/home/marietto/Scrivania/libfreenect2# nvidia-smi
| NVIDIA-SMI 470.86 Driver Version: 470.86 CUDA Version: 11.4
根据此网站:
https://stackoverflow.com/questions/6622454/cuda-incompatible-with-my-gcc-version
对于 CUDA 版本 11.1、11.2、11.3、11.4.0 ----> 最大支持的 GCC 版本 = 10
所以,我应该这样做:
MAX_GCC_VERSION=10
sudo apt install gcc-$MAX_GCC_VERSION g++-$MAX_GCC_VERSION
g++-10 is already at the most recent version available (10.3.0-11ubuntu1).
gcc-10 is already at the most recent version available (10.3.0-11ubuntu1).
sudo ln -s /usr/bin/gcc-10 /usr/lib/cuda/bin/gcc
sudo ln -s /usr/bin/gcc-$MAX_GCC_VERSION /usr/lib/cuda/bin/gcc
sudo ln -s /usr/bin/g++-$MAX_GCC_VERSION /usr/lib/cuda/bin/g++
因为我安装的cuda版本要求gcc版本不高于10。
后来,按照这个指南:
https://www.notaboutmy.life/posts/run-kinect-2-on-ubuntu-20-lts/
我应该按如下方式编译 libfreenect2:
git clone https://github.com/OpenKinect/libfreenect2.git
cd libfreenect2
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/home/marietto/Desktop/libfreenect2
不幸的是,它似乎不接受 gcc 10 来编译 libfreenect2:
marietto-BHYVE:/home/marietto/Scrivania/libfreenect2# make
[ 4%] Built target generate_resources_tool
[ 7%] Building NVCC (Device) object CMakeFiles/cuda_compile_1.dir/src/cuda_compile_1_generated_cuda_kde_depth_packet_processor.cu.o
In file included from /usr/include/cuda_runtime.h:83,
from <command-line>:
/usr/include/crt/host_config.h:139:2: error: #error -- unsupported GNU version! gcc versions later than 10 are not supported! The nvcc flag '-allow-unsupported-compiler' can be used to override this version check; however, using an unsupported host compiler may cause compilation failure or incorrect run time execution. Use at your own risk.
139 | #error -- unsupported GNU version! gcc versions later than 10 are not supported! The nvcc flag '-allow-unsupported-compiler' can be used to override this version check; however, using an unsupported host compiler may cause compilation failure or incorrect run time execution. Use at your own risk.
| ^~~~~
/home/marietto/Scrivania/libfreenect2/src/cuda_kde_depth_packet_processor.cu:39:10: fatal error: helper_math.h: File o directory non esistente
39 | #include <helper_math.h>
| ^~~~~~~~~~~~~~~
compilation terminated.
CMake Error at cuda_compile_1_generated_cuda_kde_depth_packet_processor.cu.o.RelWithDebInfo.cmake:220 (message):
Error generating
/home/marietto/Scrivania/libfreenect2/CMakeFiles/cuda_compile_1.dir/src/./cuda_compile_1_generated_cuda_kde_depth_packet_processor.cu.o
make[2]: *** [CMakeFiles/freenect2.dir/build.make:103: CMakeFiles/cuda_compile_1.dir/src/cuda_compile_1_generated_cuda_kde_depth_packet_processor.cu.o] Errore 1
make[1]: *** [CMakeFiles/Makefile2:194: CMakeFiles/freenect2.dir/all] Errore 2
make: *** [Makefile:149: all] Errore 2
答案1
通过阅读以下教程,我找到了解决方案:
和 :
但缺少“helper_math.h”文件的错误仍然存在,所以我需要开始另一篇文章。
答案2
总的来说,我发现最好坚持使用 Ubuntu LTS 版本……18.04 或 20.04 等等……因为这些版本往往能得到 nvidia 驱动程序等的更好支持
所以我在 Ubuntu 20.04 上,我通过这样做安装了 cuda
删除所有你创建的用于覆盖编译器版本的符号链接
软件和更新 -> 附加驱动程序 -> 选择 Nouveau
cd /var/crash#删除此处的所有文件
cd /etc/apt
grep -r cuda * # 为您提供示例文件 /etc/apt/sources.list.d/cuda-ubuntu2004-11-6-local.list
现在删除上述命令返回的所有文件或仅注释掉上述文件内的所有行
重启
现在安装 cuda(它将自动安装匹配的 nvidia 驱动程序,但您必须从使用 Nouveau 开始)
https://developer.nvidia.com/cuda-downloads Linux -> x86_64 -> Ubuntu -> 20.04 -> deb (本地)
以上链接
上面只是向你展示了下面你自己
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/11.6.0/local_installers/cuda-repo-ubuntu2004-11-6-local_11.6.0-510.39.01-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu2004-11-6-local_11.6.0-510.39.01-1_amd64.deb
sudo apt-key add /var/cuda-repo-ubuntu2004-11-6-local/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda
重启
nvidia-smi
Mon Jan 17 13:20:46 2022
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 510.39.01 Driver Version: 510.39.01 CUDA Version: 11.6 |
|-------------------------------+----------------------+----------------------+
| 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 ... On | 00000000:02:00.0 On | N/A |
| 0% 56C P0 29W / 190W | 1362MiB / 6144MiB | 25% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| 0 N/A N/A 1280 G /usr/lib/xorg/Xorg 101MiB |
| 0 N/A N/A 1965 G /usr/lib/xorg/Xorg 656MiB |
| 0 N/A N/A 2110 G /usr/bin/gnome-shell 82MiB |
| 0 N/A N/A 2493 G ...AAAAAAAAA= --shared-files 19MiB |
| 0 N/A N/A 4865 G ...167530988844266480,131072 19MiB |
| 0 N/A N/A 6981 G ...axaca/src/firefox/firefox 230MiB |
| 0 N/A N/A 8585 G ...AAAAAAAAA= --shared-files 39MiB |
| 0 N/A N/A 10141 G ...AAAAAAAAA= --shared-files 68MiB |
| 0 N/A N/A 10638 G ...AAAAAAAAA= --shared-files 114MiB |
+-----------------------------------------------------------------------------+
nvcc --版本
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Fri_Dec_17_18:16:03_PST_2021
Cuda compilation tools, release 11.6, V11.6.55
Build cuda_11.6.r11.6/compiler.30794723_0
cat proc/驱动程序/nvidia/版本
NVRM version: NVIDIA UNIX x86_64 Kernel Module 510.39.01 Fri Dec 31 11:03:22 UTC 2021
GCC version: gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04)
完成上述操作后,你的 git repo 就可以按照下面的方法编译成功
gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0 版权所有 (C) 2019 Free Software Foundation, Inc. 这是免费软件;请参阅来源以了解复制条件。没有任何保证;甚至对于适销性或特定用途的适用性也不提供保证。
g++ --版本
g++ (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0 版权所有 (C) 2019 Free Software Foundation, Inc. 这是免费软件;请参阅来源以了解复制条件。没有任何保证;甚至对于适销性或特定用途的适用性也不提供保证。
oaxaca@wasayama ~/src/doitt/github.com/OpenKinect/libfreenect2/build $ cmake ..
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- 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/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- using tinythread as threading library
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Checking for module 'libusb-1.0>=1.0.20'
-- Found libusb-1.0, version 1.0.23
-- Checking for modules 'libva;libva-drm'
-- Found libva, version 1.7.0
-- Found libva-drm, version 1.7.0
-- Found JPEG: /usr/lib/x86_64-linux-gnu/libjpeg.so (found version "80")
-- Could NOT find TegraJPEG (missing: TegraJPEG_LIBRARIES TegraJPEG_INCLUDE_DIRS TegraJPEG_WORKS)
-- Performing Test TURBOJPEG_WORKS
-- Performing Test TURBOJPEG_WORKS - Success
-- Found TurboJPEG: /usr/lib/x86_64-linux-gnu/libturbojpeg.so.0
-- Checking for module 'glfw3'
-- Found glfw3, version 3.3.2
CMake Warning (dev) at /usr/share/cmake-3.16/Modules/FindOpenGL.cmake:275 (message):
Policy CMP0072 is not set: FindOpenGL prefers GLVND by default when
available. Run "cmake --help-policy CMP0072" for policy details. Use the
cmake_policy command to set the policy and suppress this warning.
FindOpenGL found both a legacy GL library:
OPENGL_gl_LIBRARY: /usr/lib/x86_64-linux-gnu/libGL.so
and GLVND libraries for OpenGL and GLX:
OPENGL_opengl_LIBRARY: /usr/lib/x86_64-linux-gnu/libOpenGL.so
OPENGL_glx_LIBRARY: /usr/lib/x86_64-linux-gnu/libGLX.so
OpenGL_GL_PREFERENCE has not been set to "GLVND" or "LEGACY", so for
compatibility with CMake 3.10 and below the legacy GL library will be used.
Call Stack (most recent call first):
CMakeLists.txt:269 (FIND_PACKAGE)
This warning is for project developers. Use -Wno-dev to suppress it.
-- Found OpenGL: /usr/lib/x86_64-linux-gnu/libOpenGL.so
-- Looking for CL_VERSION_2_0
-- Looking for CL_VERSION_2_0 - found
-- Found OpenCL: /usr/lib/x86_64-linux-gnu/libOpenCL.so (found version "2.0")
-- Performing Test OpenCL_C_WORKS
-- Performing Test OpenCL_C_WORKS - Success
-- Performing Test OpenCL_CXX_WORKS
-- Performing Test OpenCL_CXX_WORKS - Success
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found CUDA: /usr/local/cuda (found version "11.6")
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- Linking with these libraries:
/usr/lib/x86_64-linux-gnu/libusb-1.0.so
pthread
va-drm
va
/usr/lib/x86_64-linux-gnu/libjpeg.so
/usr/lib/x86_64-linux-gnu/libturbojpeg.so.0
/usr/lib/x86_64-linux-gnu/libglfw.so
/usr/lib/x86_64-linux-gnu/libGL.so
/usr/lib/x86_64-linux-gnu/libOpenCL.so
/usr/local/cuda/lib64/libcudart_static.a
-lpthread
dl
/usr/lib/x86_64-linux-gnu/librt.so
-- Found Doxygen: /usr/bin/doxygen (found version "1.8.17") found components: doxygen dot
-- Configurating examples
-- Using in-tree freenect2 target
-- Checking for module 'libopenni2'
-- Found libopenni2, version 2.2.0.3
-- Found OpenNI2: /usr/lib
-- Feature list:
-- CUDA yes
-- CXX11 disabled
-- Examples yes
-- OpenCL yes
-- OpenGL yes
-- OpenNI2 yes
-- TegraJPEG no
-- Threading tinythread
-- TurboJPEG yes
-- VAAPI yes
-- VideoToolbox no (Apple only)
-- streamer_recorder disabled
-- Configuring done
-- Generating done
-- Build files have been written to: /home/oaxaca/src/doitt/github.com/OpenKinect/libfreenect2/build
文件 helper_math.h 在哪里?
oaxaca@wasayama ~/src/doitt/github.com/OpenKinect/libfreenect2/build $ make -j16
Scanning dependencies of target generate_resources_tool
[ 3%] Building CXX object CMakeFiles/generate_resources_tool.dir/tools/generate_resources.cpp.o
[ 6%] Linking CXX executable bin/generate_resources_tool
[ 6%] Built target generate_resources_tool
[ 15%] Generating resources.inc.h
[ 15%] Building NVCC (Device) object CMakeFiles/cuda_compile_1.dir/src/cuda_compile_1_generated_cuda_kde_depth_packet_processor.cu.o
[ 15%] Building NVCC (Device) object CMakeFiles/cuda_compile_1.dir/src/cuda_compile_1_generated_cuda_depth_packet_processor.cu.o
/home/oaxaca/src/doitt/github.com/OpenKinect/libfreenect2/src/cuda_depth_packet_processor.cu:31:10: fatal error: helper_math.h: No such file or directory
31 | #include <helper_math.h>
| ^~~~~~~~~~~~~~~
compilation terminated.
/home/oaxaca/src/doitt/github.com/OpenKinect/libfreenect2/src/cuda_kde_depth_packet_processor.cu:39:10: fatal error: helper_math.h: No such file or directory
39 | #include <helper_math.h>
| ^~~~~~~~~~~~~~~
compilation terminated.
CMake Error at cuda_compile_1_generated_cuda_kde_depth_packet_processor.cu.o.RelWithDebInfo.cmake:220 (message):
Error generating
/home/oaxaca/src/doitt/github.com/OpenKinect/libfreenect2/build/CMakeFiles/cuda_compile_1.dir/src/./cuda_compile_1_generated_cuda_kde_depth_packet_processor.cu.o
CMake Error at cuda_compile_1_generated_cuda_depth_packet_processor.cu.o.RelWithDebInfo.cmake:220 (message):
Error generating
/home/oaxaca/src/doitt/github.com/OpenKinect/libfreenect2/build/CMakeFiles/cuda_compile_1.dir/src/./cuda_compile_1_generated_cuda_depth_packet_processor.cu.o
make[2]: *** [CMakeFiles/freenect2.dir/build.make:84: CMakeFiles/cuda_compile_1.dir/src/cuda_compile_1_generated_cuda_kde_depth_packet_processor.cu.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [CMakeFiles/freenect2.dir/build.make:77: CMakeFiles/cuda_compile_1.dir/src/cuda_compile_1_generated_cuda_depth_packet_processor.cu.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:118: CMakeFiles/freenect2.dir/all] Error 2
make: *** [Makefile:130: all] Error 2