Ubuntu16.04+NVIDIA驱动418.56+CUDA10+CUDNN7.5.1+opencv3.4.0

重装了几次系统后,终于能含泪写下自己的安装过程,为以后重装做个记录T T

一、NVIDIA驱动

Ubuntu18.04安装英伟达显卡驱动
安装nvidia驱动418.56
Ubuntu16.04+NVIDIA驱动418.56+CUDA10+CUDNN7.5.1+opencv3.4.0_第1张图片

安装后续步骤或环境必需的依赖包,依次输入以下命令:


sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
 
sudo apt-get install --no-install-recommends libboost-all-dev
 
sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev
 
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
 
sudo apt-get install git cmake build-essential

二、CUDA

1.安装缺失的依赖库

sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libgl1-mesa-dev libglu1-mesa libglu1-mesa-dev libxi-dev

2.安装CUDA

在CUDA所在的文件夹中打开终端,输入以下命令:

sudo sh cuda_10.0.130_410.48_linux.run  

Ubuntu16.04+NVIDIA驱动418.56+CUDA10+CUDNN7.5.1+opencv3.4.0_第2张图片
按q跳过(截图没显示)

Do you accept the previously read EULA?
accept/decline/quit: accept

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 410.48?
(y)es/(n)o/(q)uit: n  ##一定要选N

Install the CUDA 10.0 Toolkit?
(y)es/(n)o/(q)uit: y

Enter Toolkit Location
 [ default is /usr/local/cuda-10.0 ]: 

Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y

Install the CUDA 10.0 Samples?
(y)es/(n)o/(q)uit: y

Enter CUDA Samples Location
 [ default is /home/srq ]: 

Installing the CUDA Toolkit in /usr/local/cuda-10.0 ...
Installing the CUDA Samples in /home/srq ...
Copying samples to /home/srq/NVIDIA_CUDA-10.0_Samples now...
Finished copying samples.

3.设置环境变量

sudo gedit ~/.bashrc

在文件末尾添加:

export PATH=/usr/local/cuda-10.0/bin:$PATH 
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64:$LD_LIBRARY_PATH
export CUDA_HOME=/usr/local/cuda
source ~/.bashrc

4.检测CUDA是否安装正确

nvcc --version
cat /usr/local/cuda/version.txt

Ubuntu16.04+NVIDIA驱动418.56+CUDA10+CUDNN7.5.1+opencv3.4.0_第3张图片
CUDA安装完成。保险起见,测试一哈:

cd /usr/local/cuda-10.0/samples
sudo make all -j16
cd ./bin/x86_64/linux/release
./deviceQuery 

Ubuntu16.04+NVIDIA驱动418.56+CUDA10+CUDNN7.5.1+opencv3.4.0_第4张图片
显示Result = PASS字样,测试通过。

三、CUDNN

1.安装CUDNN

在cudnn所在文件夹中,打开终端,运行以下命令解压:

tar -xzvf cudnn-10.0-linux-x64-v7.5.1.10.tgz 
cd cuda
cd ./include
sudo cp cudnn.h  /usr/local/cuda/include/
cd ../lib64
sudo cp lib*  /usr/local/cuda/lib64/
sudo chmod a+r /usr/local/cuda/include/cudnn.h 
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
cd /usr/local/cuda/lib64/ 
sudo rm -rf libcudnn.so libcudnn.so.7
sudo ln -s libcudnn.so.7.5.1 libcudnn.so.7
sudo ln -s libcudnn.so.7 libcudnn.so
sudo ldconfig -v

2.检测CUDNN是否安装正确

cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2

Ubuntu16.04+NVIDIA驱动418.56+CUDA10+CUDNN7.5.1+opencv3.4.0_第5张图片

四、opencv3.4.0

1.安装和编译

解压压缩包,进入解压好的opencv-3.4.0中

mkdir build 
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
sudo make all -j16

Ubuntu16.04+NVIDIA驱动418.56+CUDA10+CUDNN7.5.1+opencv3.4.0_第6张图片

sudo make install

Ubuntu16.04+NVIDIA驱动418.56+CUDA10+CUDNN7.5.1+opencv3.4.0_第7张图片

2.配置环境变量

sudo gedit /etc/ld.so.conf.d/opencv.conf 

打开的是一个空白的文件,在文件中添加

/usr/local/lib  

执行如下命令使得刚才的配置路径生效:

sudo ldconfig 

配置bash:

sudo gedit /etc/bash.bashrc 

在文件末尾添加:

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig  
export PKG_CONFIG_PATH

执行如下命令使得配置生效:

source /etc/bash.bashrc

更新:

sudo updatedb

3.测试

cd opencv-3.4.0/samples/cpp/example_cmake
cmake .
make
./opencv_example

你可能感兴趣的:(Ubuntu16.04+NVIDIA驱动418.56+CUDA10+CUDNN7.5.1+opencv3.4.0)