系统:Win10
环境:VisualStudio2022
visualStudio2022环境下简单编译opencv及freetype。
新建一个.bat文件,输入命令。
执行bat文件进行编译。
新建一个.bat文件,并输入以下代码,需要添加或者删除功能可以按照需求进行更改。
@echo off
set BUILD_DIR=vs2022-x64
if not exist %BUILD_DIR% md %BUILD_DIR%
cd %BUILD_DIR%
cmake -G "Visual Studio 17 2022" -A x64 ../.. ^
-DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_INSTALL_PREFIX=./install/opencv/4.5.5-pre ^
-DBUILD_LIST=core,imgcodecs,imgproc,highgui,photo,gapi ^
-DBUILD_TIFF=OFF ^
-DBUILD_OPENJPEG=OFF ^
-DBUILD_JASPER=OFF ^
-DBUILD_JPEG=OFF ^
-DBUILD_OPENEXR=OFF ^
-DBUILD_WEBP=OFF ^
-DBUILD_TBB=OFF ^
-DBUILD_IPP_IW=OFF ^
-DBUILD_ITT=OFF ^
-DWITH_AVFOUNDATION=OFF ^
-DWITH_CAP_IOS=OFF ^
-DWITH_CAROTENE=OFF ^
-DWITH_CPUFEATURES=OFF ^
-DWITH_EIGEN=OFF ^
-DWITH_FFMPEG=OFF ^
-DWITH_GSTREAMER=OFF ^
-DWITH_GTK=OFF ^
-DWITH_IPP=OFF ^
-DWITH_HALIDE=OFF ^
-DWITH_VULKAN=OFF ^
-DWITH_INF_ENGINE=OFF ^
-DWITH_NGRAPH=OFF ^
-DWITH_JASPER=OFF ^
-DWITH_OPENJPEG=OFF ^
-DWITH_JPEG=OFF ^
-DWITH_WEBP=OFF ^
-DWITH_OPENEXR=OFF ^
-DWITH_TIFF=OFF ^
-DWITH_OPENVX=OFF ^
-DWITH_GDCM=OFF ^
-DWITH_TBB=OFF ^
-DWITH_HPX=OFF ^
-DWITH_PTHREADS_PF=OFF ^
-DWITH_V4L=OFF ^
-DWITH_CLP=OFF ^
-DWITH_OPENCL=OFF ^
-DWITH_OPENCL_SVM=OFF ^
-DWITH_ITT=OFF ^
-DWITH_PROTOBUF=OFF ^
-DWITH_IMGCODEC_HDR=OFF ^
-DWITH_IMGCODEC_SUNRASTER=OFF ^
-DWITH_IMGCODEC_PXM=OFF ^
-DWITH_IMGCODEC_PFM=OFF ^
-DWITH_QUIRC=OFF ^
-DWITH_ANDROID_MEDIANDK=OFF ^
-DWITH_TENGINE=OFF ^
-DWITH_ONNX=OFF ^
-DBUILD_opencv_apps=OFF ^
-DBUILD_ANDROID_PROJECTS=OFF ^
-DBUILD_ANDROID_EXAMPLES=OFF ^
-DBUILD_DOCS=OFF ^
-DBUILD_EXAMPLES=OFF ^
-DBUILD_PACKAGE=OFF ^
-DBUILD_PERF_TESTS=OFF ^
-DBUILD_TESTS=OFF ^
-DBUILD_FAT_JAVA_LIB=OFF ^
-DBUILD_ANDROID_SERVICE=OFF ^
-DBUILD_JAVA=OFF ^
-DBUILD_OBJC=OFF ^
-DENABLE_PRECOMPILED_HEADERS=OFF ^
-DENABLE_FAST_MATH=OFF ^
-DCV_TRACE=OFF ^
-DBUILD_opencv_world=ON ^
-DBUILD_opencv_highgui=ON ^
-DBUILD_opencv_java=OFF ^
-DBUILD_opencv_objc=OFF ^
-DBUILD_opencv_js=OFF ^
-DBUILD_opencv_ts=OFF ^
-DBUILD_opencv_python2=OFF ^
-DBUILD_opencv_python3=OFF ^
-DBUILD_opencv_dnn=OFF ^
-DBUILD_opencv_videoio=ON ^
-DBUILD_opencv_calib3d=ON ^
-DBUILD_opencv_flann=ON ^
-DBUILD_opencv_objdetect=ON ^
-DBUILD_opencv_stitching=ON ^
-DBUILD_opencv_ml=OFF ^
-DCV_DISABLE_OPTIMIZATION=ON ^
-DWITH_VTK=OFF ^
-DWITH_CUDA=OFF ^
-DCMAKE_FIND_DEBUG_MODE=FALSE
cmake --build . --config Debug -j8
cmake --build . --config Release -j8
cmake --install . --config Debug
cmake --install . --config Release
cd ..
pause
新建一个.bat文件,并输入以下代码,需要添加或者删除功能可以按照需求进行更改。
@echo off
set BUILD_DIR=vs2022-x86
if not exist %BUILD_DIR% md %BUILD_DIR%
cd %BUILD_DIR%
cmake -G "Visual Studio 17 2022" -A win32 ../.. ^
-DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_INSTALL_PREFIX=./install/opencv/4.5.5-pre ^
-DBUILD_LIST=core,imgcodecs,imgproc,highgui,photo,gapi ^
-DBUILD_TIFF=OFF ^
-DBUILD_OPENJPEG=OFF ^
-DBUILD_JASPER=OFF ^
-DBUILD_JPEG=OFF ^
-DBUILD_OPENEXR=OFF ^
-DBUILD_WEBP=OFF ^
-DBUILD_TBB=OFF ^
-DBUILD_IPP_IW=OFF ^
-DBUILD_ITT=OFF ^
-DWITH_AVFOUNDATION=OFF ^
-DWITH_CAP_IOS=OFF ^
-DWITH_CAROTENE=OFF ^
-DWITH_CPUFEATURES=OFF ^
-DWITH_EIGEN=OFF ^
-DWITH_FFMPEG=OFF ^
-DWITH_GSTREAMER=OFF ^
-DWITH_GTK=OFF ^
-DWITH_IPP=OFF ^
-DWITH_HALIDE=OFF ^
-DWITH_VULKAN=OFF ^
-DWITH_INF_ENGINE=OFF ^
-DWITH_NGRAPH=OFF ^
-DWITH_JASPER=OFF ^
-DWITH_OPENJPEG=OFF ^
-DWITH_JPEG=OFF ^
-DWITH_WEBP=OFF ^
-DWITH_OPENEXR=OFF ^
-DWITH_TIFF=OFF ^
-DWITH_OPENVX=OFF ^
-DWITH_GDCM=OFF ^
-DWITH_TBB=OFF ^
-DWITH_HPX=OFF ^
-DWITH_PTHREADS_PF=OFF ^
-DWITH_V4L=OFF ^
-DWITH_CLP=OFF ^
-DWITH_OPENCL=OFF ^
-DWITH_OPENCL_SVM=OFF ^
-DWITH_ITT=OFF ^
-DWITH_PROTOBUF=OFF ^
-DWITH_IMGCODEC_HDR=OFF ^
-DWITH_IMGCODEC_SUNRASTER=OFF ^
-DWITH_IMGCODEC_PXM=OFF ^
-DWITH_IMGCODEC_PFM=OFF ^
-DWITH_QUIRC=OFF ^
-DWITH_ANDROID_MEDIANDK=OFF ^
-DWITH_TENGINE=OFF ^
-DWITH_ONNX=OFF ^
-DBUILD_opencv_apps=OFF ^
-DBUILD_ANDROID_PROJECTS=OFF ^
-DBUILD_ANDROID_EXAMPLES=OFF ^
-DBUILD_DOCS=OFF ^
-DBUILD_EXAMPLES=OFF ^
-DBUILD_PACKAGE=OFF ^
-DBUILD_PERF_TESTS=OFF ^
-DBUILD_TESTS=OFF ^
-DBUILD_FAT_JAVA_LIB=OFF ^
-DBUILD_ANDROID_SERVICE=OFF ^
-DBUILD_JAVA=OFF ^
-DBUILD_OBJC=OFF ^
-DENABLE_PRECOMPILED_HEADERS=OFF ^
-DENABLE_FAST_MATH=OFF ^
-DCV_TRACE=OFF ^
-DBUILD_opencv_world=ON ^
-DBUILD_opencv_highgui=ON ^
-DBUILD_opencv_java=OFF ^
-DBUILD_opencv_objc=OFF ^
-DBUILD_opencv_js=OFF ^
-DBUILD_opencv_ts=OFF ^
-DBUILD_opencv_python2=OFF ^
-DBUILD_opencv_python3=OFF ^
-DBUILD_opencv_dnn=OFF ^
-DBUILD_opencv_videoio=ON ^
-DBUILD_opencv_calib3d=ON ^
-DBUILD_opencv_flann=ON ^
-DBUILD_opencv_objdetect=ON ^
-DBUILD_opencv_stitching=ON ^
-DBUILD_opencv_ml=OFF ^
-DCV_DISABLE_OPTIMIZATION=ON ^
-DWITH_VTK=OFF ^
-DWITH_CUDA=OFF ^
-DCMAKE_FIND_DEBUG_MODE=FALSE
cmake --build . --config Debug -j8
cmake --build . --config Release -j8
cmake --install . --config Debug
cmake --install . --config Release
cd ..
pause
新建一个.bat文件,并输入以下代码,需要添加或者删除功能可以按照需求进行更改。
@echo off
set BUILD_DIR=vs2022-x64
if not exist %BUILD_DIR% md %BUILD_DIR%
cd %BUILD_DIR%
cmake -G "Visual Studio 17 2022" -A x64 ../.. ^
-DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_INSTALL_PREFIX=./install/opencv/4.5.5-pre ^
-DBUILD_LIST=core,imgcodecs,imgproc,highgui,photo,gapi,freetype ^
-DOPENCV_EXTRA_MODULES_PATH=D:/compile_work/opencv_code/opencv_contrib/modules ^
-DFREETYPE_INCLUDE_DIRS=D:/compile_work/freetype-2.13.2/build/vs2022-x64/install/freetype/2.13.2/include/freetype2 ^
-DFREETYPE_LIBRARY_DEBUG=D:/compile_work/freetype-2.13.2/build/vs2022-x64/install/freetype/2.13.2/lib/freetyped.lib ^
-DFREETYPE_LIBRARY_RELEASE=D:/compile_work/freetype-2.13.2/build/vs2022-x64/install/freetype/2.13.2/lib/freetype.lib ^
-DHARFBUZZ_INCLUDE_DIRS=D:/compile_work/harfbuzz-8.2.2/build/vs2022-x64/install/harfbuzz/8.2.2/include/harfbuzz ^
-DHARFBUZZ_LIBRARY_DEBUG=D:/compile_work/harfbuzz-8.2.2/build/vs2022-x64/install/harfbuzz/8.2.2/lib/harfbuzzd.lib ^
-DHARFBUZZ_LIBRARY_Release=D:/compile_work/harfbuzz-8.2.2/build/vs2022-x64/install/harfbuzz/8.2.2/lib/harfbuzz.lib ^
-DBUILD_TIFF=OFF ^
-DBUILD_OPENJPEG=OFF ^
-DBUILD_JASPER=OFF ^
-DBUILD_JPEG=OFF ^
-DBUILD_OPENEXR=OFF ^
-DBUILD_WEBP=OFF ^
-DBUILD_TBB=OFF ^
-DBUILD_IPP_IW=OFF ^
-DBUILD_ITT=OFF ^
-DWITH_AVFOUNDATION=OFF ^
-DWITH_CAP_IOS=OFF ^
-DWITH_CAROTENE=OFF ^
-DWITH_CPUFEATURES=OFF ^
-DWITH_EIGEN=OFF ^
-DWITH_FFMPEG=OFF ^
-DWITH_GSTREAMER=OFF ^
-DWITH_GTK=OFF ^
-DWITH_IPP=OFF ^
-DWITH_HALIDE=OFF ^
-DWITH_VULKAN=OFF ^
-DWITH_INF_ENGINE=OFF ^
-DWITH_NGRAPH=OFF ^
-DWITH_JASPER=OFF ^
-DWITH_OPENJPEG=OFF ^
-DWITH_JPEG=OFF ^
-DWITH_WEBP=OFF ^
-DWITH_OPENEXR=OFF ^
-DWITH_TIFF=OFF ^
-DWITH_OPENVX=OFF ^
-DWITH_GDCM=OFF ^
-DWITH_TBB=OFF ^
-DWITH_HPX=OFF ^
-DWITH_PTHREADS_PF=OFF ^
-DWITH_V4L=OFF ^
-DWITH_CLP=OFF ^
-DWITH_OPENCL=OFF ^
-DWITH_OPENCL_SVM=OFF ^
-DWITH_ITT=OFF ^
-DWITH_PROTOBUF=OFF ^
-DWITH_IMGCODEC_HDR=OFF ^
-DWITH_IMGCODEC_SUNRASTER=OFF ^
-DWITH_IMGCODEC_PXM=OFF ^
-DWITH_IMGCODEC_PFM=OFF ^
-DWITH_QUIRC=OFF ^
-DWITH_ANDROID_MEDIANDK=OFF ^
-DWITH_TENGINE=OFF ^
-DWITH_ONNX=OFF ^
-DBUILD_opencv_apps=OFF ^
-DBUILD_ANDROID_PROJECTS=OFF ^
-DBUILD_ANDROID_EXAMPLES=OFF ^
-DBUILD_DOCS=OFF ^
-DBUILD_EXAMPLES=OFF ^
-DBUILD_PACKAGE=OFF ^
-DBUILD_PERF_TESTS=OFF ^
-DBUILD_TESTS=OFF ^
-DBUILD_FAT_JAVA_LIB=OFF ^
-DBUILD_ANDROID_SERVICE=OFF ^
-DBUILD_JAVA=OFF ^
-DBUILD_OBJC=OFF ^
-DENABLE_PRECOMPILED_HEADERS=OFF ^
-DENABLE_FAST_MATH=OFF ^
-DCV_TRACE=OFF ^
-DBUILD_opencv_world=ON ^
-DBUILD_opencv_highgui=ON ^
-DBUILD_opencv_java=OFF ^
-DBUILD_opencv_objc=OFF ^
-DBUILD_opencv_js=OFF ^
-DBUILD_opencv_ts=OFF ^
-DBUILD_opencv_python2=OFF ^
-DBUILD_opencv_python3=OFF ^
-DBUILD_opencv_dnn=OFF ^
-DBUILD_opencv_videoio=ON ^
-DBUILD_opencv_calib3d=ON ^
-DBUILD_opencv_flann=ON ^
-DBUILD_opencv_objdetect=ON ^
-DBUILD_opencv_stitching=ON ^
-DBUILD_opencv_ml=OFF ^
-DCV_DISABLE_OPTIMIZATION=ON ^
-DWITH_VTK=OFF ^
-DWITH_CUDA=OFF ^
-DCMAKE_FIND_DEBUG_MODE=FALSE
cmake --build . --config Debug -j8
cmake --build . --config Release -j8
cmake --install . --config Debug
cmake --install . --config Release
cd ..
pause
新建一个.bat文件,并输入以下代码。
@echo off
set BUILD_DIR=vs2022-x64
if not exist %BUILD_DIR% md %BUILD_DIR%
cd %BUILD_DIR%
cmake ../.. -G "Visual Studio 17 2022" -A x64 ^
-DCMAKE_INSTALL_PREFIX=./install/freetype/2.13.2 ^
-DFT_WITH_BZIP2=OFF ^
-DFT_WITH_HARFBUZZ=OFF ^
-DFT_WITH_PNG=OFF ^
-DFT_WITH_ZLIB=OFF
cmake --build . --config Debug
cmake --build . --config Release
cmake --install . --config Debug
cmake --install . --config Release
cd ..
pause
新建一个.bat文件,并输入以下代码。
@echo off
set BUILD_DIR=vs2022-x86
if not exist %BUILD_DIR% md %BUILD_DIR%
cd %BUILD_DIR%
cmake ../.. -G "Visual Studio 17 2022" -A Win32 ^
-DCMAKE_GENERATOR_TOOLSET=v142 ^
-DCMAKE_INSTALL_PREFIX=./install/freetype/2.13.2 ^
-DFT_WITH_BZIP2=OFF ^
-DFT_WITH_HARFBUZZ=OFF ^
-DFT_WITH_PNG=OFF ^
-DFT_WITH_ZLIB=OFF
cmake --build . --config Debug
cmake --build . --config Release
cmake --install . --config Debug
cmake --install . --config Release
cd ..
pause
使用.bat及visualstudio编译的说明。
cmake ../.. -G "Visual Studio 17 2022" 是使用vs2022进行编译,取决于当前主机环境
cmake ../.. -G "Visual Studio 16 2019" 是使用vs2019进行编译
-A Win32 是指定编译x86的库
-A x64 是指定编译x64的库
-DCMAKE_GENERATOR_TOOLSET=v142 是指定使用平台工具集为v142,取决于当前主机支持的版本
-DCMAKE_GENERATOR_TOOLSET=v143 是指定使用平台工具集为v143