OpenCV學(xué)習筆記(3)用VS2008編譯OpenCV2.0源代碼(編譯錯誤已解決) 收藏 此文于2009-10-09被推薦到CSDN首頁(yè)
如何被推薦?
20091027-Update:
參考于仕琪老師《VC 2008 Express下安裝OpenCV2.0》作適當修改。
OpenCV2.0.0今天發(fā)布了,我馬上趕去下載嘗鮮,不過(guò)安裝后才發(fā)現,這個(gè)版本的 bin 和 lib 都是未經(jīng)編譯、還不能直接使用的。通過(guò) 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 點(diǎn)擊configure按鈕,選擇相應的編譯器為visual studio 9 2008,點(diǎn)擊finish,出現紅色標記的參數。
2.3 再點(diǎn)configur按鈕,參數消除了紅色。
2.4 點(diǎn)擊generator按鈕,生成工程文件。
3. 用vc2008進(jìn)行編譯
完成上一步驟后,將在C:/opencv2.0/vs2008build目錄下生成OpenCV.sln的VC Solution File,請用VS2008打開(kāi)OpenCV.sln,然后執行如下操作:
在Debug下,選擇Solution Explorer里的 Solution OpenCV,點(diǎn)右鍵,運行"Rebuild Solution";如編譯無(wú)錯誤,再選擇INSTALL項目,運行"Build"。
在Release下,選擇Solution Explorer里的 Solution OpenCV,點(diǎn)右鍵,運行"Rebuild Solution";如編譯無(wú)錯誤,再選擇INSTALL項目,運行"Build"。
此時(shí),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動(dòng)態(tài)庫生成完畢。
下面是原來(lái)的編譯方法,不大合適,會(huì )產(chǎn)生編譯錯誤。
3.1 用vc2008打開(kāi)產(chǎn)生的工程文件OpenCV.sln,打開(kāi)batch build菜單,全選中,然后Build (這個(gè)過(guò)程大概要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中刪除,不過(guò)似乎這種方式不大好。在 OpenCV 中文論壇發(fā)起提問(wèn),得到回復如下:
“按以下方式編譯可以解決:
運行Cmake gui,設定生成的目標路徑為opencv安裝路徑。”
不過(guò)按此方法,仍然不能解決問(wèn)題。希望大家多多指教,怎么解決這個(gè)編譯問(wèn)題?
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請
點(diǎn)擊舉報。