OpenCV学习笔记(3)用VS2008编译OpenCV2.0源代码(编译错误已解决)

来源:百度文库 编辑:神马文学网 时间:2024/04/28 22:15:01
OpenCV学习笔记(3)用VS2008编译OpenCV2.0源代码(编译错误已解决) 收藏 此文于2009-10-09被推荐到CSDN首页
如何被推荐?
20091027-Update:参考于仕琪老师《VC 2008 Express下安装OpenCV2.0》作适当修改。OpenCV2.0.0今天发布了,我马上赶去下载尝鲜,不过安装后才发现,这个版本的 bin 和 lib 都是未经编译、还不能直接使用的。通过 OpenCV 中文论坛得知,要使用 Cmake 软件对 OpenCV 源代码重新编译,才能得到最终的 dll 和 lib 文件。编译方法如下:1. 假设OpenCV2.0安装于以下目录: C:/opencv2.0。
2. 使用CMake建立VC工程文件
   2.1 运行Cmake gui
        Where is the source code: C:/opencv2.0
        Where to build the binaries: C:/opencv2.0/vs2008build(自己新建此目录)
   2.2 点击configure按钮,选择相应的编译器为visual studio 9 2008,点击finish,出现红色标记的参数。
   2.3 再点configur按钮,参数消除了红色。
   2.4 点击generator按钮,生成工程文件。
3. 用vc2008进行编译
完成上一步骤后,将在C:/opencv2.0/vs2008build目录下生成OpenCV.sln的VC Solution File,请用VS2008打开OpenCV.sln,然后执行如下操作: 在Debug下,选择Solution Explorer里的 Solution OpenCV,点右键,运行"Rebuild Solution";如编译无错误,再选择INSTALL项目,运行"Build"。
在Release下,选择Solution Explorer里的 Solution OpenCV,点右键,运行"Rebuild Solution";如编译无错误,再选择INSTALL项目,运行"Build"。
此时,OpenCV的*d.dll文件(for debug)和*.dll文件(for release)将出现在C:/opencv2.0/vs2008build\bin目录中;OpenCV的*d.lib文件(for debug)和*.lib文件(for release)将出现在C:/opencv2.0/vs2008build\lib目录;头文件*.h出现在C:/opencv2.0/vs2008build\include\opencv中。 可以被VS2008调用的OpenCV动态库生成完毕。下面是原来的编译方法,不大合适,会产生编译错误。   3.1 用vc2008打开产生的工程文件OpenCV.sln,打开batch build菜单,全选中,然后Build (这个过程大概要6、7分钟)
   3.2 出现以下错误:------ Build started: Project: RUN_TESTS, Configuration: Release Win32 ------
Performing Post-Build Event...
Start processing tests
Test project D:/OpenCV2.0/build
  1/  3 Testing cvtest                        Could not find executable D:/OpenCV2.0/build/bin/$(OutDir)/cvtest.exe
Looked in the following places:
D:/OpenCV2.0/build/bin/$(OutDir)/cvtest.exe
D:/OpenCV2.0/build/bin/$(OutDir)/cvtest.exe.exe
D:/OpenCV2.0/build/bin/$(OutDir)/Release/cvtest.exe
D:/OpenCV2.0/build/bin/$(OutDir)/Release/cvtest.exe.exe
Release/D:/OpenCV2.0/build/bin/$(OutDir)/cvtest.exe
Release/D:/OpenCV2.0/build/bin/$(OutDir)/cvtest.exe.exe
Unable to find executable: D:/OpenCV2.0/build/bin/$(OutDir)/cvtest.exe
  2/  3 Testing cxcoretest                    Could not find executable D:/OpenCV2.0/build/bin/$(OutDir)/cxcoretest.exe
Looked in the following places:
D:/OpenCV2.0/build/bin/$(OutDir)/cxcoretest.exe
D:/OpenCV2.0/build/bin/$(OutDir)/cxcoretest.exe.exe
D:/OpenCV2.0/build/bin/$(OutDir)/Release/cxcoretest.exe
D:/OpenCV2.0/build/bin/$(OutDir)/Release/cxcoretest.exe.exe
Release/D:/OpenCV2.0/build/bin/$(OutDir)/cxcoretest.exe
Release/D:/OpenCV2.0/build/bin/$(OutDir)/cxcoretest.exe.exe
Unable to find executable: D:/OpenCV2.0/build/bin/$(OutDir)/cxcoretest.exe
  3/  3 Testing mltest                        Could not find executable D:/OpenCV2.0/build/bin/$(OutDir)/mltest.exe
Looked in the following places:
D:/OpenCV2.0/build/bin/$(OutDir)/mltest.exe
D:/OpenCV2.0/build/bin/$(OutDir)/mltest.exe.exe
D:/OpenCV2.0/build/bin/$(OutDir)/Release/mltest.exe
D:/OpenCV2.0/build/bin/$(OutDir)/Release/mltest.exe.exe
Release/D:/OpenCV2.0/build/bin/$(OutDir)/mltest.exe
Release/D:/OpenCV2.0/build/bin/$(OutDir)/mltest.exe.exe
Unable to find executable: D:/OpenCV2.0/build/bin/$(OutDir)/mltest.exe
0% tests passed, 3 tests failed out of 3
The following tests FAILED:
   1 - cvtest (Not Run)
   2 - cxcoretest (Not Run)
   3 - mltest (Not Run)
Errors while running CTest
Project : error PRJ0019: A tool returned an error code from "Performing Post-Build Event..."解决方法之一是:将RUN_TESTS项目从solution中删除,不过似乎这种方式不大好。在 OpenCV 中文论坛发起提问,得到回复如下:“按以下方式编译可以解决:
运行Cmake gui,设定生成的目标路径为opencv安装路径。”不过按此方法,仍然不能解决问题。希望大家多多指教,怎么解决这个编译问题? 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/chenyusiyuan/archive/2009/09/30/4623675.aspx