编译OpenCV缺少python27_d.lib的解决方法

错误 24error LNK1104: 无法打开文件“python27_d.lib”  C:\OpenCV\VS2013_64\modules\python\LINK opencv_python


一个妥协的方法是注释掉会使用python27_d.lib部分的代码,替换为使用python27.lib


具体做法如下:

在OpenCV项目的bindings中的opencv_python项目中,点击“外部依赖项”,在其中找到pyconfig.h和object.h文件:

pyconfig.h中

[cpp]  view plain  copy
  1. #ifdef _DEBUG  
  2. #   define Py_DEBUG  
  3. #endif  
修改为:

[cpp]  view plain  copy
  1. #ifdef _DEBUG  
  2. //# define Py_DEBUG  
  3. #endif  

[cpp]  view plain  copy
  1. /* For an MSVC DLL, we can nominate the .lib files used by extensions */  
  2. #ifdef MS_COREDLL  
  3. #   ifndef Py_BUILD_CORE /* not building the core - must be an ext */  
  4. #       if defined(_MSC_VER)  
  5.             /* So MSVC users need not specify the .lib file in 
  6.             their Makefile (other compilers are generally 
  7.             taken care of by distutils.) */  
  8. #           ifdef _DEBUG  
  9. #               pragma comment(lib,"python27_d.lib")  
  10. #           else  
  11. #               pragma comment(lib,"python27.lib")  
  12. #           endif /* _DEBUG */  
  13. #       endif /* _MSC_VER */  
  14. #   endif /* Py_BUILD_CORE */  
  15. #endif /* MS_COREDLL */  
修改为

[cpp]  view plain  copy
  1. /* For an MSVC DLL, we can nominate the .lib files used by extensions */  
  2. #ifdef MS_COREDLL  
  3. #   ifndef Py_BUILD_CORE /* not building the core - must be an ext */  
  4. #       if defined(_MSC_VER)  
  5.             /* So MSVC users need not specify the .lib file in 
  6.             their Makefile (other compilers are generally 
  7.             taken care of by distutils.) */  
  8. #           ifdef _DEBUG  
  9. #               pragma comment(lib,"python27.lib")  
  10. #           else  
  11. #               pragma comment(lib,"python27.lib")  
  12. #           endif /* _DEBUG */  
  13. #       endif /* _MSC_VER */  
  14. #   endif /* Py_BUILD_CORE */  
  15. #endif /* MS_COREDLL */  
object.h中


[cpp]  view plain  copy
  1. /* Py_DEBUG implies Py_TRACE_REFS. */  
  2. #if defined(Py_DEBUG) && !defined(Py_TRACE_REFS)  
  3. #define Py_TRACE_REFS  
  4. #endif  
修改为

[cpp]  view plain  copy
  1. /* Py_DEBUG implies Py_TRACE_REFS. */  
  2. #if defined(Py_DEBUG) && !defined(Py_TRACE_REFS)  
  3. //#define Py_TRACE_REFS  
  4. #endif  


保存之后,再次编译就成功啦!

转载来源:http://blog.csdn.net/pplxlee/article/details/78067927

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要添加python_viz.hpp头文件,需要在编译OpenCV时启用Python支持,并使用CMake将相关的选项设置为ON。 具体步骤如下: 1. 确保已经安装了Python和相关的开发库,例如Python-dev或Python3-dev。 2. 下载OpenCV源代码,进入源代码目录。 3. 创建一个build目录,并进入该目录: ``` mkdir build cd build ``` 4. 使用CMake生成Makefile: ``` cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D INSTALL_C_EXAMPLES=OFF \ -D OPENCV_ENABLE_NONFREE=ON \ -D WITH_CUDA=OFF \ -D WITH_CUDNN=OFF \ -D WITH_TBB=ON \ -D ENABLE_FAST_MATH=1 \ -D CUDA_FAST_MATH=0 \ -D WITH_OPENMP=ON \ -D WITH_OPENGL=ON \ -D WITH_EIGEN=ON \ -D PYTHON_DEFAULT_EXECUTABLE=$(which python) \ -D PYTHON_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \ -D PYTHON_LIBRARY=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \ -D PYTHON3_DEFAULT_EXECUTABLE=$(which python3) \ -D PYTHON3_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \ -D PYTHON3_LIBRARY=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \ -D BUILD_opencv_python3=ON \ .. ``` 其中,`-D BUILD_opencv_python3=ON`选项用于启用Python3支持。 5. 执行make命令进行编译: ``` make -j4 ``` 6. 安装OpenCV: ``` sudo make install ``` 7. 在Python中使用python_viz.hpp头文件: ``` import cv2 from cv2 import viz # 在此处使用viz相关的函数 ``` 注意,在使用python_viz.hpp时,还需要确保已经安装了vtk和vtk-dev库。在Ubuntu上,可以使用以下命令进行安装: ``` sudo apt-get install libvtk7-dev sudo apt-get install vtk7 ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值