2011-09-21 72 views
2

我正在建立一臺OpenCV 2.3.1的新機器。該機器是Windows 7機器,我遵循OpenCV網站(使用CMake和MinGW構建)提供的安裝說明。OpenCV你好,世界不編譯它應該

這裏是我的代碼:

#include <iostream> 
#include <opencv2/core/core.hpp> 
#include <opencv2/highgui/highgui.hpp> 
int main() { 
    char var; 
    cv::Mat img; 
    img = cv::imread("C:/test/img.jpg"); 
    cv::namedWindow("Image"); 
    cv::imshow("Image", img); 
    std::cin >> var; 
    return 1; 
} 

這裏是我的make命令:

g++ -o main main.cpp -lopencv_core -lopencv_imgproc -lopencv_calib3d -lopencv_video -lopencv_features2d -lopencv_ml -lopencv_highgui -lopencv_objdetect -lopencv_contrib -lopencv_legacy 

這裏是我的路徑:

C:\OpenCV-2.3.1\install\bin;C:\OpenCV-2.3.1\install\include;C:\QtSDK\QtCreator\bin;C:\Program Files (x86)\MiKTeX 2.9\miktex\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\CMake 2.8\bin;C:\QtSDK\mingw\bin; 

這裏是我的錯誤:

main.cpp:2:33: error: opencv2/core/core.hpp: No such file or directory 
main.cpp:3:39: error: opencv2/highgui/highgui.hpp: No such file or directory 
main.cpp: In function 'int main()': 
main.cpp:8: error: 'cv' has not been declared 
main.cpp:8: error: expected ';' before 'img' 
main.cpp:9: error: 'img' was not declared in this scope 
main.cpp:9: error: 'cv' has not been declared 
main.cpp:10: error: 'cv' has not been declared 
main.cpp:11: error: 'cv' has not been declared 

這是沒有道理的。爲什麼不能編譯?爲什麼找不到opencv2/core/core.hpp?

+0

你能不能張貼一個鏈接到你的指令遵循? –

回答

2

g++在查找包含文件時不考慮%PATH%(在Unix上爲$PATH)。

添加以下編譯命令:-IC:\OpenCV-2.3.1\install\include

g++ -IC:\OpenCV-2.3.1\install\include -o main main.cpp -lopencv_core ... 
+0

這也是QT創建者編譯不正確的疑難解答......那裏有同樣的問題嗎? – shoes

+0

@shoes:最有可能的。 – NPE

0

您還沒有包括正確的OpenCV的目錄。

我做的C:\OpenCV2.3以前版本的OpenCV的安裝,而這些都是我不得不添加了我的編譯器,找到頭的路徑:

C:\OpenCV2.3\build\include\opencv 

C:\OpenCV2.3\build\include\opencv2 

C:\OpenCV2.3\build\include 

傳統,G ++需要標題目錄與-I標誌,您似乎根本沒有使用該標誌。

0

就像Unix操作系統

 g++ filename.cpp -o exec `pkg-config opencv cvblob --libs --cflags` 

(cvblob可選,如果你檢查BLOB)