首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >编译OpenCV on Link1181错误,python3.obj而不是python3.lib

编译OpenCV on Link1181错误,python3.obj而不是python3.lib
EN

Stack Overflow用户
提问于 2022-01-19 11:25:57
回答 1查看 274关注 0票数 0

我正在尝试编译带有CUDA / CuDNN支持的CuDNN Python库,主要使用可用的指南这里,而步骤5:构建OpenCV遇到了麻烦。

我安装了:

  • Visual 2022与Windows 10 SDK和桌面开发工具包。
  • CMake (v3.22.1)
  • CuDNN (v8.3)
  • CUDA (v11.6)

克隆OpenCV回购并检查版本4.5.5之后,我创建了一个名为opencv_env的Anaconda虚拟环境,然后启动:

代码语言:javascript
复制
set cwd=%cd%
set envName=opencv_env
set opencv-version=4.5.5

conda activate %envName%
set CONDA_PREFIX=%CONDA_PREFIX:\=/%

cd %cwd%

mkdir OpenCV-%opencv-version%
cd opencv
mkdir build
cd build

cmake ^
-G "Visual Studio 17 2022" ^
-T host=x64 ^
-DCMAKE_BUILD_TYPE=RELEASE ^
-DCMAKE_INSTALL_PREFIX=%cwd%/OpenCV-%opencv-version% ^
-DOPENCV_EXTRA_MODULES_PATH=%cwd%/opencv_contrib/modules ^
-DINSTALL_PYTHON_EXAMPLES=OFF ^
-DINSTALL_C_EXAMPLES=OFF ^
-DPYTHON_EXECUTABLE=%CONDA_PREFIX%/python3 ^
-DPYTHON3_LIBRARY=%CONDA_PREFIX%/libs/python3.lib ^
-DWITH_CUDA=ON ^
-DWITH_CUDNN=ON ^
-DCUDNN_INCLUDE_DIR=C:\NVIDIA\CUDNN\v8.3\include ^
-DCUDNN_LIBRARY=C:\NVIDIA\CUDNN\v8.3\lib\x64\cudnn.lib ^
-DCUDNN_VERSION='8.3' ^
-DOPENCV_DNN_CUDA=ON ^
-DWITH_CUBLAS=ON ^
-DWITH_NGRAPH=ON ^
..

它基本上将CMake配置为编译,我得到了以下内容:

代码语言:javascript
复制
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
-- Detected processor: AMD64
-- libjpeg-turbo: VERSION = 2.1.2, BUILD = opencv-4.5.5-libjpeg-turbo
-- Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1). OpenJPEG will be built from sources
-- OpenJPEG: VERSION = 2.4.0, BUILD = opencv-4.5.5-openjp2-2.4.0
-- OpenJPEG libraries will be built from sources: libopenjp2 (version "2.4.0")
-- found Intel IPP (ICV version): 2020.0.0 [2020.0.0 Gold]
-- at: C:/Users/XXX/opencv/build/3rdparty/ippicv/ippicv_win/icv
-- found Intel IPP Integration Wrappers sources: 2020.0.0
-- at: C:/Users/XXX/opencv/build/3rdparty/ippicv/ippicv_win/iw
-- CUDA detected: 11.6
-- CUDA: Using CUDA_ARCH_BIN=3.5;3.7;5.0;5.2;6.0;6.1;7.0;7.5;8.0;8.6
-- CUDA NVCC target flags: -gencode;arch=compute_35,code=sm_35;-gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_52,code=sm_52;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_61,code=sm_61;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_80,code=sm_80;-gencode;arch=compute_86,code=sm_86;-D_FORCE_INLINES
-- CUDA: MSVS generator is detected. Disabling CMake re-run checks (CMAKE_SUPPRESS_REGENERATION=ON). You need to run CMake XXXally if updates are required.
-- Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
-- Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
-- Could NOT find BLAS (missing: BLAS_LIBRARIES)
-- Could NOT find LAPACK (missing: LAPACK_LIBRARIES)
    Reason given by package: LAPACK could not be found because dependency BLAS could not be found.

-- Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
-- VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
-- Module opencv_alphamat disabled because the following dependencies are not found: Eigen
-- freetype2:   NO
-- harfbuzz:    NO
-- Julia not found. Not compiling Julia Bindings.
-- Module opencv_ovis disabled because OGRE3D was not found
-- No preference for use of exported gflags CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported gflags CMake configuration if available.
-- Failed to find installed gflags CMake configuration, searching for gflags build directories exported with CMake.
-- Failed to find gflags - Failed to find an installed/exported CMake configuration for gflags, will perform search for installed gflags components.
-- Failed to find gflags - Could not find gflags include directory, set GFLAGS_INCLUDE_DIR to directory containing gflags/gflags.h
-- Failed to find glog - Could not find glog include directory, set GLOG_INCLUDE_DIR to directory containing glog/logging.h
-- Module opencv_sfm disabled because the following dependencies are not found: Eigen Glog/Gflags
-- Tesseract:   NO
-- Allocator metrics storage type: 'long long'
-- Registering hook 'INIT_MODULE_SOURCES_opencv_dnn': C:/Users/XXX/opencv/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.rvv.cpp
-- imgcodecs: OpenEXR codec is disabled in runtime. Details: https://github.com/opencv/opencv/issues/21326
-- highgui: using builtin backend: WIN32UI
-- rgbd: Eigen support is disabled. Eigen is Required for Posegraph optimization
-- Building with NVIDIA Optical Flow API 2.0
-- Found 'misc' Python modules from C:/Users/XXX/opencv/modules/python/package/extra_modules
-- Found 'mat_wrapper;utils' Python modules from C:/Users/XXX/opencv/modules/core/misc/python/package
-- Found 'gapi' Python modules from C:/Users/XXX/opencv/modules/gapi/misc/python/package
-- Found 'misc' Python modules from C:/Users/XXX/opencv/modules/python/package/extra_modules
-- Found 'mat_wrapper;utils' Python modules from C:/Users/XXX/opencv/modules/core/misc/python/package
-- Found 'gapi' Python modules from C:/Users/XXX/opencv/modules/gapi/misc/python/package
CMake Warning at cmake/OpenCVGenSetupVars.cmake:54 (message):
  CONFIGURATION IS NOT SUPPORTED: validate setupvars script in install
  directory
Call Stack (most recent call first):
  CMakeLists.txt:1035 (include)


--
-- General configuration for OpenCV 4.5.5 =====================================
--   Version control:               4.5.5
--
--   Extra modules:
--     Location (extra):            C:/Users/XXX/opencv_contrib/modules
--     Version control (extra):     4.5.5
--
--   Platform:
--     Timestamp:                   2022-01-17T19:05:56Z
--     Host:                        Windows 10.0.19042 AMD64
--     CMake:                       3.22.1
--     CMake generator:             Visual Studio 17 2022
--     CMake build tool:            C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe
--     MSVC:                        1930
--     Configuration:               Debug Release
--
--   CPU/HW features:
--     Baseline:                    SSE SSE2 SSE3
--       requested:                 SSE3
--     Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
--       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
--       SSE4_1 (18 files):         + SSSE3 SSE4_1
--       SSE4_2 (2 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
--       FP16 (1 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
--       AVX (5 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
--       AVX2 (33 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
--       AVX512_SKX (8 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
--
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ standard:                11
--     C++ Compiler:                C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.30.30705/bin/Hostx64/x64/cl.exe  (ver 19.30.30709.0)
--     C++ flags (Release):         /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP  /MD /O2 /Ob2 /DNDEBUG
--     C++ flags (Debug):           /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP  /MDd /Zi /Ob0 /Od /RTC1
--     C Compiler:                  C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.30.30705/bin/Hostx64/x64/cl.exe
--     C flags (Release):           /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /MP   /MD /O2 /Ob2 /DNDEBUG
--     C flags (Debug):             /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /MP /MDd /Zi /Ob0 /Od /RTC1
--     Linker flags (Release):      /machine:x64  /INCREMENTAL:NO
--     Linker flags (Debug):        /machine:x64  /debug /INCREMENTAL
--     ccache:                      NO
--     Precompiled headers:         YES
--     Extra dependencies:          cudart_static.lib nppc.lib nppial.lib nppicc.lib nppidei.lib nppif.lib nppig.lib nppim.lib nppist.lib nppisu.lib nppitc.lib npps.lib cublas.lib cudnn.lib cufft.lib -LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.6/lib/x64 -LIBPATH:C:/NVIDIA/CUDNN/v8.3/lib/x64
--     3rdparty dependencies:
--
--   OpenCV modules:
--     To be built:                 aruco barcode bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 alphamat cvv freetype hdf java julia matlab ovis python2 sfm viz
--     Applications:                tests perf_tests apps
--     Documentation:               NO
--     Non-free algorithms:         NO
--
--   Windows RT support:            NO
--
--   GUI:                           WIN32UI
--     Win32 UI:                    YES
--     VTK support:                 NO
--
--   Media I/O:
--     ZLib:                        build (ver 1.2.11)
--     JPEG:                        build-libjpeg-turbo (ver 2.1.2-62)
--     WEBP:                        build (ver encoder: 0x020f)
--     PNG:                         build (ver 1.6.37)
--     TIFF:                        build (ver 42 - 4.2.0)
--     JPEG 2000:                   build (ver 2.4.0)
--     OpenEXR:                     build (ver 2.3.0)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
--
--   Video I/O:
--     DC1394:                      NO
--     FFMPEG:                      YES (prebuilt binaries)
--       avcodec:                   YES (58.134.100)
--       avformat:                  YES (58.76.100)
--       avutil:                    YES (56.70.100)
--       swscale:                   YES (5.9.100)
--       avresample:                YES (4.0.0)
--     GStreamer:                   NO
--     DirectShow:                  YES
--     Media Foundation:            YES
--       DXVA:                      YES
--
--   Parallel framework:            Concurrency
--
--   Trace:                         YES (with Intel ITT)
--
--   Other third-party libraries:
--     Intel IPP:                   2020.0.0 Gold [2020.0.0]
--            at:                   C:/Users/XXX/opencv/build/3rdparty/ippicv/ippicv_win/icv
--     Intel IPP IW:                sources (2020.0.0)
--               at:                C:/Users/XXX/opencv/build/3rdparty/ippicv/ippicv_win/iw
--     Lapack:                      NO
--     nGraph:                      NO
--     Eigen:                       NO
--     Custom HAL:                  NO
--     Protobuf:                    build (3.19.1)
--
--   NVIDIA CUDA:                   YES (ver 11.6, CUFFT CUBLAS)
--     NVIDIA GPU arch:             35 37 50 52 60 61 70 75 80 86
--     NVIDIA PTX archs:
--
--   cuDNN:                         YES (ver 8.3)
--
--   OpenCL:                        YES (NVD3D11)
--     Include path:                C:/Users/XXX/opencv/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
--
--   Python 3:
--     Interpreter:                 C:/Users/XXX/.conda/envs/opencv_env/python.exe (ver 3.9.7)
--     Libraries:                   C:/Users/XXX/.conda/envs/opencv_env/libs/python3 (ver 3.9.7)
--     numpy:                       C:/Users/XXX/.conda/envs/opencv_env/lib/site-packages/numpy/core/include (ver 1.22.1)
--     install path:                C:/Users/XXX/.conda/envs/opencv_env/Lib/site-packages/cv2/python-3.9
--
--   Python (for build):            C:/Users/XXX/.conda/envs/opencv_env/python.exe
--
--   Java:
--     ant:                         NO
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO
--
--   Install to:                    C:/Users/XXX/OpenCV-4.5.5
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/XXX/opencv/build

很好,我想。但在建筑时:

代码语言:javascript
复制
cmake --build . --config Release --target INSTALL

我得到了以下信息:

代码语言:javascript
复制
Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 pour .NET Framework
Copyright (C) Microsoft Corporation. Tous droits réservés.

  libopenjp2.vcxproj -> C:\Users\XXX\opencv\build\3rdparty\lib\Release\libopenjp2.lib
  [LOTS OF TEXT CUT HERE, compiling stuff to lib, dll and exe files]
  opencv_waldboost_detector.vcxproj -> C:\Users\XXX\opencv\build\bin\Release\opencv_waldboost_detector.exe
LINK : fatal error LNK1181: impossible d'ouvrir le fichier en entrée 'C:\Users\XXX\.conda\envs\opencv_env\libs\python3.obj' [C:\Users\XXX\opencv\build\modules\python3\opencv_python3.vcxproj]

一切都很顺利,直到出现LNK1181致命错误。据我所知,错误来自于不可能打开C:\Users\XXX\.conda\envs\opencv_env\libs\python3.obj,而这实际上并不存在。这个位置上的文件是python3.lib,而不是

我试图将.lib添加到PYTHON3_LIBRARY CMake行的末尾:

-DPYTHON3_LIBRARY=%CONDA_PREFIX%/libs/python3.lib

但是链接器仍然搜索一个.obj文件。是否有办法迫使链接器接受.lib文件?(假设这是我提到的错误的真正原因),如果是,怎么做?

EN

回答 1

Stack Overflow用户

发布于 2022-09-07 02:37:15

我做了以下工作来克服这个问题(我用OpenCV-4.6.0安装进行了测试,并确认它运行良好):

  1. python3.lib复制到同一目录中的python3.obj
  2. python3.libpython310.lib复制到../opencv/build/modules/python3
  3. 重新启动cmake构建(我没有先清理/卸载)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70769753

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档