2013-04-26 124 views
1

我已經QT安裝在我的電腦,它是使用Visual Studio 2010的編譯器未找到文件main.obj

enter image description here

我用一個簡單的Hello World應用程序進行了測試,它工作正常。

但是現在我正嘗試在QT中使用OpenCV。我已經安裝了Visual Studio 2010 express和professional,並且opencv在那裏工作得很好。但是,當我嘗試運行QT OpenCV的,我得到以下錯誤

main.obj:-1: error: LNK2019: unresolved external symbol "public: void __thiscall cv::Mat::deallocate(void)" ([email protected]@[email protected]@QAEXXZ) referenced in function "public: void __thiscall cv::Mat::release(void)" ([email protected]@[email protected]@QAEXXZ) 

main.obj:-1: error: LNK2019: unresolved external symbol "void __cdecl cv::fastFree(void *)" ([email protected]@@[email protected]) referenced in function "public: __thiscall cv::Mat::~Mat(void)" ([email protected]@@[email protected]) 

main.obj:-1: error: LNK2019: unresolved external symbol "int __cdecl cv::waitKey(int)" ([email protected]@@[email protected]) referenced in function _main 

    main.obj:-1: error: LNK2019: unresolved external symbol "void __cdecl cv::imshow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class cv::_InputArray const &)" ([email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z) referenced in function _main 

    main.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall cv::_InputArray::_InputArray(class cv::Mat const &)" ([email protected]@@[email protected]@[email protected]@Z) referenced in function _main 

    main.obj:-1: error: LNK2019: unresolved external symbol "void __cdecl cv::namedWindow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" ([email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]) referenced in function _main 

    main.obj:-1: error: LNK2019: unresolved external symbol "class cv::Mat __cdecl cv::imread(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" ([email protected]@@[email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]) referenced in function _main 

    release\FirstProject.exe:-1: error: LNK1120: 7 unresolved externals 

以下是我FirstProject.pro文件的內容

#------------------------------------------------- 
# 
# Project created by QtCreator 2013-04-26T11:15:33 
# 
#------------------------------------------------- 

QT  += core 

QT  -= gui 

TARGET = FirstProject 
CONFIG += console 
CONFIG -= app_bundle 

TEMPLATE = app 


SOURCES += main.cpp 

INCLUDEPATH += C:\opencv\build\include\ 
LIBS += -LC:\opencv\build\x86\vc10\lib \ 
-lopencv_calib3d240d.lib\ 
-lopencv_contrib240d.lib\ 
-lopencv_core240d.lib\ 
-lopencv_features2d240d.lib\ 
-lopencv_flann240d.lib\ 
-lopencv_gpu240d.lib\ 
-lopencv_haartraining_engined.lib\ 
-lopencv_highgui240d.lib\ 
-lopencv_imgproc240d.lib\ 
-lopencv_legacy240d.lib\ 
-lopencv_ml240d.lib\ 
-lopencv_nonfree240d.lib\ 
-lopencv_objdetect240d.lib\ 
-lopencv_photo240d.lib\ 
-lopencv_stitching240d.lib\ 
-lopencv_ts240d.lib\ 
-lopencv_video240d.lib\ 
-lopencv_videostab240d.lib 

我試圖chainging以下FirstProject。親內容,但在所有

#------------------------------------------------- 
# 
# Project created by QtCreator 2013-04-26T11:15:33 
# 
#------------------------------------------------- 

QT  += core 

QT  -= gui 

TARGET = FirstProject 
CONFIG += console 
CONFIG -= app_bundle 

TEMPLATE = app 


SOURCES += main.cpp 

INCLUDEPATH += C:\opencv\build\include\ 
LIBS += -LC:\opencv\build\x86\vc10\lib \ 
-lopencv_core240 \ 
-lopencv_highgui240 \ 
-lopencv_imgproc240 \ 
-lopencv_features2d240 \ 
-lopencv_calib3d240 

下面沒有好是我的代碼

的main.cpp

#include <iostream> 
#include <opencv2/core/core.hpp> 
#include <opencv2/highgui/highgui.hpp> 

using namespace std; 
using namespace cv; 

int main() 
{ 

    Mat image = imread("D:/Tulips.jpg"); 

    if(!image.data) 
    { 
     cout << "Error loading image" << endl; 
    } 
    else 
    { 
     namedWindow("Image"); 
     imshow("Image",image); 
    } 

    waitKey(0); 
    return 0; 

} 

爲什麼會出現這個錯誤?請幫我擺脫這個問題

回答

1

我找到了答案。解決此問題的唯一方法是逐個添加庫,並使用完整路徑

LIBS += C:/opencv/build/x86/vc9/lib/opencv_calib3d240.lib 
LIBS += C:/opencv/build/x86/vc9/lib/opencv_contrib240.lib 
+0

有趣的是,如果您持有'CTRL'並將鼠標懸停在庫名稱上,則Qt檢測到的成功將導致鼠標變爲手形圖標 – user3079474 2015-04-05 09:04:08

2

QT項目文件試圖統一處理文件/目錄分隔符,即前向v的反斜槓。使用哪一個應該沒有關係。但是,也許有一些翻譯正在進行。

嘗試用正向版本'/'替換所有反斜槓'\'。 Qmake會適當地轉換它們。

替換-LC:/opencv/build/x86/vc10/lib

它也可能是您的INCLUDEPATH這就是問題的最終反斜槓。也許它正在加入下一行?

+0

感謝您的回覆。我是否還必須在每個庫包含行的末尾都轉換所有「\」? – 2013-04-26 06:50:25

+0

每個包含行結尾的「\」是告訴qmake當前包含尚未結束。如果你刪除它,你將不得不做類似「LIBS + = -LC:/ opencv/build/x86/vc10/lib LIBS + = -lopencv_core240 LIBS + = ...」 – 2013-04-26 07:18:30

+0

要解釋YamHon.CHAN,是的,你確實需要每條LIBS線的反斜線來繼續這條線。然而,INCLUDEPATH行不需要它,因爲你沒有繼續該行,並且在目錄上結尾的斜線(後退或前進)是不必要的。 – 2013-04-28 23:33:18