MSYS静态编译opencv-4.4.0时注意事项

1.protobuf
  如果已经安装过protobuf时,make时会发生错误,解决方法是已经安装的protobuf的头文件包含的目录临时改名
2.jpeg2000
  链接opencv_perf_imgproc.exe时发成错误,解决方法是cmake-gui成功完成后,在cvconfig.h文件中增加
  #define OPJ_STATIC 1
然后编译应用程序时需要追加 -lopenjp2
make -j8 就OK啦

 

opencv从3.4版本没有.pc文件文件
自己写了 opencv440.pc 供参考
----------------------------------------------------------------------
# Package Information for pkg-config
Name: OpenCV
Description: Open Source Computer Vision Library
Version: 4.4.0
Libs: -L/usr/opt/opencv-4.4.0/x64/mingw/staticlib -lopencv_world440
Libs.private: -L/usr/opt/opencv-4.4.0/x64/mingw/staticlib -llibjpeg -llibpng -llibtiff -lIlmImf -L/usr/local/lib -lwebp -lvfw32 -lwinmm -lcomctl32 -lgdi32 -lole32 -lsetupapi -lws2_32 -lstdc++ -lglu32 -lopengl32 -lzlib -lopenjp2
Cflags: -I/usr/opt/opencv-4.4.0/include/opencv -I/usr/opt/opencv-4.4.0/include
----------------------------------------------------------------------

 测试是否编译成功

#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
 Mat image(600, 800, CV_8UC3, Scalar(100, 250, 30)); 
 String windowName = "Window with Blank Image";
 namedWindow(windowName);
 imshow(windowName, image);
 waitKey(0);
 destroyWindow(windowName);
 return 0;
}

编译链接

version=opencv
version=opencv220
version=opencv2413
version=opencv300
version=opencv3411
version=opencv440

OCV_CXXFLAGS=`pkg-config --cflags --static $version`
OCV_LIBS=`pkg-config --libs --static $version`
OCV_LIBS=${OCV_LIBS}" -lcomdlg32 -lgdi32 -lcomctl32"

echo OCV_CXXFLAGS = $OCV_CXXFLAGS
echo OCV_LIBS     = $OCV_LIBS

echo CC;g++ -c opencv.cc $OCV_CXXFLAGS && \
echo LINK;g++ -g opencv.o -o opencv-g $OCV_LIBS -static

cp opencv-g.exe opencv.exe && \
echo STRIP; strip opencv.exe

运行exe文件,验证编译的库文件是否正常;

最后不要忘记改过名的 local/include/google/protobuf ,改回原来的名字

posted @ 2020-09-09 18:31  1CM  阅读(430)  评论(0编辑  收藏  举报