2011-08-09 138 views
4

我在Windows 7 64位和Netbeans 7.0中使用的OpenCV。我試着使用MinGW和cygwin編譯下一個代碼,但是兩個都失敗並導致未定義的引用。OpenCV的2.3不能編譯,未定義的引用錯誤

當我使用MAT或FLANN和其他人我不能編譯,但我將所有的庫(我試過只增加調試者,發佈者,才需要的...但失敗)。

在Ubuntu相同的代碼工作,但我需要編譯它在Windows了。我使用2.3編譯版本(使用CMake)和可安裝版本。

#include "opencv2\opencv.hpp" 
#include <iostream> 

using namespace std; 

int main(void) 
{ 
    cv::Mat::eye(1, 1, 0); 

    return 0; 
} 

"/usr/bin/make" -f nbproject/Makefile-Release.mk QMAKE= SUBPROJECTS= .clean-conf 
make[1]: Entering directory `/cygdrive/f/Proyectos/C++/OpenCV23Sandbox' 
rm -f -r build/Release 
rm -f dist/Release/Cygwin-Windows/opencv23sandbox.exe 
make[1]: Leaving directory `/cygdrive/f/Proyectos/C++/OpenCV23Sandbox' 

CLEAN SUCCESSFUL (total time: 1s) 
"/usr/bin/make" -f nbproject/Makefile-Release.mk QMAKE= SUBPROJECTS= .build-conf 
make[1]: Entering directory `/cygdrive/f/Proyectos/C++/OpenCV23Sandbox' 
"/usr/bin/make" -f nbproject/Makefile-Release.mk dist/Release/Cygwin-Windows/opencv23sandbox.exe 
make[2]: Entering directory `/cygdrive/f/Proyectos/C++/OpenCV23Sandbox' 
mkdir -p build/Release/Cygwin-Windows 
rm -f build/Release/Cygwin-Windows/main.o.d 
g++.exe -c -O2 -I/cygdrive/C/OpenCV2.3/build/include -MMD -MP -MF build/Release/Cygwin-Windows/main.o.d -o build/Release/Cygwin-Windows/main.o main.cpp 
mkdir -p dist/Release/Cygwin-Windows 
g++.exe  -o dist/Release/Cygwin-Windows/opencv23sandbox build/Release/Cygwin-Windows/main.o -L/cygdrive/C/OpenCV2.3/build/x86/vc10/lib -lopencv_calib3d230 -lopencv_calib3d230d -lopencv_contrib230 -lopencv_contrib230d -lopencv_core230 -lopencv_core230d -lopencv_features2d230 -lopencv_features2d230d -lopencv_flann230 -lopencv_flann230d -lopencv_gpu230 -lopencv_gpu230d -lopencv_haartraining_engine -lopencv_haartraining_engined -lopencv_highgui230 -lopencv_highgui230d -lopencv_imgproc230 -lopencv_imgproc230d -lopencv_legacy230 -lopencv_legacy230d -lopencv_ml230 -lopencv_ml230d -lopencv_objdetect230 -lopencv_objdetect230d -lopencv_video230 -lopencv_video230d 
build/Release/Cygwin-Windows/main.o:main.cpp:(.text+0xac): undefined reference to `cv::Mat::eye(int, int, int)' 
build/Release/Cygwin-Windows/main.o:main.cpp:(.text+0x106): undefined reference to `cv::fastFree(void*)' 
build/Release/Cygwin-Windows/main.o:main.cpp:(.text+0x16f): undefined reference to `cv::fastFree(void*)' 
build/Release/Cygwin-Windows/main.o:main.cpp:(.text+0x1dd): undefined reference to `cv::fastFree(void*)' 
build/Release/Cygwin-Windows/main.o:main.cpp:(.text+0x1fa): undefined reference to `cv::Mat::deallocate()' 
build/Release/Cygwin-Windows/main.o:main.cpp:(.text+0x20a): undefined reference to `cv::Mat::deallocate()' 
build/Release/Cygwin-Windows/main.o:main.cpp:(.text+0x21a): undefined reference to `cv::Mat::deallocate()' 
build/Release/Cygwin-Windows/main.o:main.cpp:(.text$_ZN2cv3MatD1Ev[cv::Mat::~Mat()]+0x66): undefined reference to `cv::Mat::deallocate()' 
build/Release/Cygwin-Windows/main.o:main.cpp:(.text$_ZN2cv3MatD1Ev[cv::Mat::~Mat()]+0x5e): undefined reference to `cv::fastFree(void*)' 
collect2: ld returned 1make[2]: Leaving directory `/cygdrive/f/Proyectos/C++/OpenCV23Sandbox' 
make[1]: Leaving directory `/cygdrive/f/Proyectos/C++/OpenCV23Sandbox' 
exit status 
make[2]: *** [dist/Release/Cygwin-Windows/opencv23sandbox.exe] Error 1 
make[1]: *** [.build-conf] Error 2 
make: *** [.build-impl] Error 2 

BUILD FAILED (exit value 2, total time: 2s) 

使用MinGW庫試圖:

"/bin/make" -f nbproject/Makefile-Release.mk QMAKE= SUBPROJECTS= .clean-conf 
make[1]: Entering directory `/f/Proyectos/C++/OpenCV23Sandbox' 
rm -f -r build/Release 
rm -f dist/Release/MinGW-Windows/opencv23sandbox.exe 
make[1]: Leaving directory `/f/Proyectos/C++/OpenCV23Sandbox' 

CLEAN SUCCESSFUL (total time: 350ms) 
"/bin/make" -f nbproject/Makefile-Release.mk QMAKE= SUBPROJECTS= .build-conf 
make[1]: Entering directory `/f/Proyectos/C++/OpenCV23Sandbox' 
"/bin/make" -f nbproject/Makefile-Release.mk dist/Release/MinGW-Windows/opencv23sandbox.exe 
make[2]: Entering directory `/f/Proyectos/C++/OpenCV23Sandbox' 
mkdir -p build/Release/MinGW-Windows 
rm -f build/Release/MinGW-Windows/main.o.d 
g++.exe -c -O2 -I/C/OpenCV2.3/build/include -MMD -MP -MF build/Release/MinGW-Windows/main.o.d -o build/Release/MinGW-Windows/main.o main.cpp 
mkdir -p dist/Release/MinGW-Windows 
g++.exe  -o dist/Release/MinGW-Windows/opencv23sandbox build/Release/MinGW-Windows/main.o -L../OpenCV/OpenCV2.3/build/x86/mingw/lib ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_calib3d230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_contrib230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_core230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_features2d230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_flann230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_gpu230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_highgui230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_imgproc230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_legacy230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_ml230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_objdetect230.dll.a ../OpenCV/OpenCV2.3/build/x86/mingw/lib/libopencv_video230.dll.a 
build/Release/MinGW-Windows/main.o:main.cpp:(.text+0x4f): undefined reference to `cv::Mat::eye(int, int, int)' 
build/Release/MinGW-Windows/main.o:main.cpp:(.text+0xac): undefined reference to `cv::fastFree(void*)' 
build/Release/MinGW-Windows/main.o:main.cpp:(.text+0x11a): undefined reference to `cv::fastFree(void*)' 
build/Release/MinGW-Windows/main.o:main.cpp:(.text+0x191): undefined reference to `cv::fastFree(void*)' 
build/Release/MinGW-Windows/main.o:main.cpp:(.text+0x1a7): undefined reference to `cv::Mat::deallocate()' 
build/Release/MinGW-Windows/main.o:main.cpp:(.text+0x1ba): undefined reference to `cv::Mat::deallocate()' 
build/Release/MinGW-Windows/main.o:main.cpp:(.text+0x1ce): undefined reference to `cv::Mat::deallocate()' 
build/Release/MinGW-Windows/main.o:main.cpp:(.text$_ZN2cv3MatD1Ev[cv::Mat::~Mat()]+0x74): undefined reference to `cv::Mat::deallocate()' 
build/Release/MinGW-Windows/main.o:main.cpp:(.text$_ZN2cv3MatD1Ev[cv::Mat::~Mat()]+0x63): undefined reference to `cv::fastFree(void*)' 
collect2: ld returned 1 exit status 
make[2]: Leaving directory `/f/Proyectos/C++/OpenCV23Sandbox' 
make[1]: Leaving directory `/f/Proyectos/C++/OpenCV23Sandbox' 
make[2]: *** [dist/Release/MinGW-Windows/opencv23sandbox.exe] Error 1 
make[1]: *** [.build-conf] Error 2 
make: *** [.build-impl] Error 2 

BUILD FAILED (exit value 2, total time: 1s) 

g++.exe  -o dist/Release/MinGW-Windows/opencv23sandbox build/Release/MinGW-Windows/main.o -L../OpenCV/OpenCV2.3/build/x86/mingw/lib -lopencv_calib3d230.dll -lopencv_contrib230.dll -lopencv_core230.dll -lopencv_features2d230.dll -lopencv_flann230.dll -lopencv_gpu230.dll -lopencv_highgui230.dll -lopencv_imgproc230.dll -lopencv_legacy230.dll -lopencv_ml230.dll -lopencv_objdetect230.dll -lopencv_video230.dll 

相同的結果。

回答

3

你使用預編譯的MinGW庫嗎? (看起來如此)。我嘗試了幾天,讓我的項目在Code :: Blocks下成功鏈接。我看到了你描述的相同類型的錯誤(錯誤的引用等)。

我終於重新編譯的OpenCV使用here所示的步驟,都成了很好。

+0

ü...我在Windows 7中,我試過之前和除cv :: Mat或cv之外的所有作品:flann,我添加了libreries ...嗯,我會試着用MinGW而不是VS10編譯它們。 – Wiliam

+0

已經工作了,謝謝。 – Wiliam

3

我想問題是庫路徑指向vc10目錄(-L/cygdrive/C/OpenCV2.3/build/x86/vc10/lib)而不是mingw目錄(-L/cygdrive/C/OpenCV2.3/build/x86/mingw/lib)。 ld-linker找不到方法,因爲它們被vC++「link.exe」損壞。

如果您使用64位,那麼您也可以鏈接到64位庫: -L/cygdrive/C/OpenCV2.3/build/x64/mingw/lib

+0

感謝但沒有工作:( – Wiliam

+0

您是否使用64位窗口?那麼您必須鏈接到64位版本:'-L/cygdrive/C/OpenCV2.3/build/x64/mingw/lib'。 – vstm

+0

使用64位的庫僅用於優化,無論如何我嘗試了它和同樣的錯誤。再次感謝。 – Wiliam

0

我有完全相同的問題。我想用MinGW在64位Windows 7機器下編譯我的程序。下面是幾種可能性,可能導致問題:

1)你必須確保OpenCV2.3/build/x64/mingw/lib鏈接。請小心,不要將項目鏈接到Visual Studio的庫或x86的libs庫。

2)確保正確的dll被複制到項目目錄,或者已被添加到PATH。例如,如果你使用這個lib libopencv_core243.dll.a,你應該確保libopencv_core243.dll可以被項目加載。這不是問題的原因。但我認爲知道這一點也很重要。

3)確保MinGW的可以編譯x64程序。這是我使用的:mingw-w64(但是因爲mingw-w64項目正在轉向mingw-w64.org,所以最好使用新網站)。不幸的是,從MinGW32下載的那個不起作用。 MinGW的official site的鏈接將帶你到第二個(MinGW32)。

4)默認情況下,MinGw可能會將您的項目編譯爲32位程序。爲了確保它編譯爲64位,請添加此編譯標誌-m64。否則,如果您只將項目與所有64位庫鏈接,則也會導致該問題。

相關問題