升级gcc
sudo su
yum -y install wget
yum -y install vim
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
cp CentOS7-Base-163.repo /etc/yum.repos.d/
cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.bak
mv CentOS7-Base-163.repo CentOS-Base.repo
yum clean all
yum makecache
yum update
yum -y install centos-release-scl
yum -y install devtoolset-8-gcc devtoolset-8-gcc-c++ devtoolset-8-binutils
echo "source /opt/rh/devtoolset-8/enable" >>/etc/profile
source /etc/profile
安装cmake(使用【二进制】安装,yum安装的版本太低了)
sudo su
chmod 755 cmake-3.23.4-linux-x86_64.sh
./cmake-3.23.4-linux-x86_64.sh
cat >> /etc/profile <<"EOF"
export PATH=/home/user/cmake/bin:$PATH
EOF
source /etc/profile
动态库
unzip opencv-4.5.5.zip
unzip opencv_contrib-4.5.5.zip
cd opencv-4.5.5/
mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D WITH_TBB=OFF \
-D WITH_CUDA=OFF \
-D WITH_V4L=ON \
-D WITH_QT=OFF \
-D WITH_OPENGL=ON \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.5.5/modules \
-D BUILD_JAVA=OFF \
-D BUILD_OBJC=OFF \
-D BUILD_TESTS=OFF \
-D BUILD_opencv_java_bindings_generator=OFF \
-D BUILD_opencv_js_bindings_generator=OFF \
-D BUILD_opencv_objc_bindings_generator=OFF \
-D BUILD_opencv_python3=OFF \
-D BUILD_opencv_python_bindings_generator=OFF \
-D BUILD_opencv_python_test=OFF \
-D BUILD_EXAMPLES=OFF ..
make -j4
sudo make install
sudo sh -c 'echo "/usr/local/lib64" >> /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
cat >> ~/.bashrc <<"EOF"
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib64/pkgconfig
export PKG_CONFIG_PATH
EOF
source ~/.bashrc
静态库
cd opencv-4.0.1/
mkdir build && cd build
cmake \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=~/opencv_401_static_centos \
-D BUILD_SHARED_LIBS=OFF \
-D BUILD_DOCS=OFF \
-D BUILD_TESTS=OFF \
-D BUILD_FAT_JAVA_LIB=OFF \
-D BUILD_opencv_java=OFF \
-D BUILD_opencv_python=OFF \
-D BUILD_opencv_ts=OFF \
-D BUILD_PERF_TESTS=OFF \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D BUILD_JAVA=OFF \
-D BUILD_OBJC=OFF \
-D BUILD_opencv_java_bindings_generator=OFF \
-D BUILD_opencv_js_bindings_generator=OFF \
-D BUILD_opencv_objc_bindings_generator=OFF \
-D BUILD_opencv_python3=OFF \
-D BUILD_opencv_python_bindings_generator=OFF \
-D BUILD_opencv_python_test=OFF \
-D BUILD_EXAMPLES=OFF \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.0.1/modules \
-D BUILD_PNG=ON \
-D BUILD_JASPER=ON \
-D BUILD_JPEG=ON \
-D BUILD_TIFF=ON \
-D BUILD_ZLIB=ON \
-D WITH_JPEG=ON \
-D WITH_PNG=ON \
-D WITH_JASPER=ON \
-D WITH_TIFF=ON \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_OPENEXR=ON \
-D BUILD_opencv_world=ON \
..
自己写的程序生成静态库链接时:先链接静态库的静态库,再链接本静态库。
链接库顺序:
cmake中要注意链接的顺序,libopencv_imgproc.a,libopencv_core.a对libzlib.a存在依赖,应该把libzlib.a放在后面,libopencv_highgui.a读写图片还需要liblibjpeg.a等图像解码库的支持,liblibjpeg.a也要放在后面。
在项目开发过层中尽量让lib是垂直关系,避免循环依赖;越是底层的库,越是往后面写!例如:
g++ ... obj($?) -l(上层逻辑lib) -l(中间封装lib) -l(基础lib) -l(系统lib) -o $@
target_link_libraries(project ${OPENCV_LIBS} z rt pthread m dl )
去除stdc++库的依赖
grep -ir "stdc++" /usr/local/share
sudo vi /usr/local/share/OpenCV/OpenCVModules-release.cmake
IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE "opencv_core;opencv_imgproc;-static-libstdc++;dl;m;pthread;rt"
合并静态库
ar x A.a
ar x B.a
ar rc C.a *.o
参考:https://blog.csdn.net/meng_zhi_xiang/article/details/125998833
参考:https://blog.csdn.net/tywwwww/article/details/126998311
sudo yum -y update
sudo yum -y install epel-release
sudo yum -y install python36
sudo yum -y install python3-devel
python3.6 -V
pip3.6 -V
sudo python3 -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade pip
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python==4.4.0
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple Cython flask Flask-RESTful gevent greenlet pandas Pillow
# 获取模块位置
import requests
print(requests.__path__)
Centos 解决 ImportError: xxx: cannot open shared object file
| yum whatprovides XXX.so.1
[wangsp@localhost ocr_module_py]$ python3 test.py
Traceback (most recent call last):
File "test_gcn_dll.py", line 3, in <module>
import cv2
File "/home/wangsp/.local/lib/python3.6/site-packages/cv2/__init__.py", line 5, in <module>
from .cv2 import *
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
[wangsp@localhost ocr_module_py]$ yum whatprovides libGL.so.1
Loaded plugins: fastestmirror
Determining fastest mirrors
* centos-sclo-rh: centos.ccns.ncku.edu.tw
* centos-sclo-sclo: mirrors.aliyun.com
* epel: ftp.yz.yamagata-u.ac.jp
1:libglvnd-glx-1.0.1-0.8.git5baa1e5.el7.i686 : GLX support for libglvnd
Repo : base
Matched from:
Provides : libGL.so.1
[wangsp@localhost ocr_module_py]$ sudo yum install libglvnd-glx-1.0.1-0.8.git5baa1e5.el7