sudo ldconfig
Ubuntu 上cmake编译OpenCV,遇到一个错误:
usr/include/c++/6/cstdlib:75:25: fatal error: stdlib.h: 没有那个文件或目录
很是奇怪,百度搜索了下,得知是GCC6的一个改动造成的。
自己的gcc是6.3.0
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local .. -DENABLE_PRECOMPILED_HEADERS=OFF
****make 当中遇到的问题*****************
1、/home/pikachu/dev/opencv-2.4.9/modules/contrib/src/chamfermatching.cpp: In member function ‘void cv::ChamferMatcher::Matching::computeDistanceTransform(cv::Mat&, cv::Mat&, cv::Mat&, float, float, float)’:/home/pikachu/dev/opencv-2.4.9/modules/contrib/src/chamfermatching.cpp:969:30: error: the compiler can assume that the address of ‘annotate_img’ will never be NULL [-Werror=address]
if (&annotate_img!=NULL) { ^/home/pikachu/dev/opencv-2.4.9/modules/contrib/src/chamfermatching.cpp:1016:34: error: the compiler can assume that the address of ‘annotate_img’ will never be NULL [-Werror=address] if (&annotate_img!=NULL) { ^/home/pikachu/dev/opencv-2.4.9/modules/contrib/src/chamfermatching.cpp: In member function ‘cv::ChamferMatcher::Match* cv::ChamferMatcher::Matching::localChamferDistance(cv::Point, cv::Mat&, cv::Mat&, cv::ChamferMatcher::Template*, float)’:/home/pikachu/dev/opencv-2.4.9/modules/contrib/src/chamfermatching.cpp:1111:25: error: the compiler can assume that the address of ‘orientation_img’ will never be NULL [-Werror=address] if (&orientation_img!=NULL) { ^/home/pikachu/dev/opencv-2.4.9/modules/contrib/src/chamfermatching.cpp:1111:5: warning: nonnull argument ‘orientation_img’ compared to NULL [-Wnonnull-compare] if (&orientation_img!=NULL) { ^~/home/pikachu/dev/opencv-2.4.9/modules/contrib/src/chamfermatching.cpp: In member function ‘void cv::ChamferMatcher::Matching::computeDistanceTransform(cv::Mat&, cv::Mat&, cv::Mat&, float, float, float)’:/home/pikachu/dev/opencv-2.4.9/modules/contrib/src/chamfermatching.cpp:1016:17: warning: nonnull argument ‘annotate_img’ compared to NULL [-Wnonnull-compare] if (&annotate_img!=NULL) { ^~/home/pikachu/dev/opencv-2.4.9/modules/contrib/src/chamfermatching.cpp:969:13: warning: nonnull argument ‘annotate_img’ compared to NULL [-Wnonnull-compare] if (&annotate_img!=NULL) { ^~cc1plus: some warnings being treated as errorsmodules/contrib/CMakeFiles/opencv_contrib.dir/build.make:158: recipe for target 'modules/contrib/CMakeFiles/opencv_contrib.dir/src/chamfermatching.cpp.o' failedmake[2]: *** [modules/contrib/CMakeFiles/opencv_contrib.dir/src/chamfermatching.cpp.o] Error 1CMakeFiles/Makefile2:3195: recipe for target 'modules/contrib/CMakeFiles/opencv_contrib.dir/all' failedmake[1]: *** [modules/contrib/CMakeFiles/opencv_contrib.dir/all] Error 2
解决办法:
-Werror=address
,然后重新
首先:配置环境
将opencv的库加入到路径,从而让系统可以找到
sudo gedit /etc/ld.so.conf.d/opencv.conf
末尾加入/usr/local/lib,保存退出
sudo ldconfig 使配置生效sudo gedit /etc/bash.bashrc
末尾加入
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfigexport PKG_CONFIG_PATH
保存退出
sudo source /etc/bash.bashrc #使配置生效sudo passwd root(设置root密码,如果之前没有设置过)
输入新密码
su(进入root权限)
输入密码
source /etc/bash.bashrc
exit(退出root)
)
sudo updatedb #更新database
g++ helloworld.cpp -o helloworld `pkg-config --cflags --libs opencv` (注意ESC下面的`,不是单引号)(注意后面的依赖库)
编译通过后再运行
./helloworld hello.jpg
即可看到图片显示,安装完成。