2016-03-19 5 views
0

Ich habe Opencv für Codeblocks installiert und das Programm läuft gut in Codeblocks. Aber wenn ich versuche, das Programm von Eingabeaufforderung ausführen, bekomme ich einen Fehler als fatal error:opencv2/opencv.hpp No such file or directory compilation terminatedUndefinierter Referenzfehler mit OpenCV in Codeblocks für Windows

So lief ich den Befehl als

g++ -IC:\opencv\build\include -o main.exe main.cpp 

Und ich bekomme viele undefinierte Referenz errors.I haben sogar versucht, die Verknüpfung Bibliotheken als

g++ -IC:\opencv\build\include -LC:\opencv\build\x86\mingw\lib -o main.exe main.cpp 

Noch bekomme ich gleiche errors.I Verwendung OpenCV 2.4.5.I nicht Option -l verwendet haben, da es viele Bibliotheken sind und ich weiß nicht, wie all diese Bibliotheken zu verknüpfen (Verzeichnis) auf einmal.

Dies ist die Kompilierausgabe.

C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x6d): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0xb7): undefined reference to `cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x152): undefined reference to `cv::Mat::zeros(int, int, int)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x322): undefined reference to `cv::noArray()' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x384): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x3bd): undefined reference to `cv::meanStdDev(cv::_InputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, cv::_InputArray const&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x5c7): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x5ea): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x645): undefined reference to `cv::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x665): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x685): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x6d6): undefined reference to `cv::threshold(cv::_InputArray const&, cv::_OutputArray const&, double, double, int)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x705): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x752): undefined reference to `cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x775): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x7c2): undefined reference to `cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x7e5): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x808): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x828): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x86e): undefined reference to `cv::inpaint(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, double, int)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x89e): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x8be): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x910): undefined reference to `cv::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x92a): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x971): undefined reference to `cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0xc68): undefined reference to `cv::namedWindow(std::string const&, int)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0xcee): undefined reference to `cv::imread(std::string const&, int)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0xd3f): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0xd8c): undefined reference to `cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0xe05): undefined reference to `cv::operator-(cv::Scalar_<double> const&, cv::Mat const&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0xe6b): undefined reference to `cv::operator+(cv::Mat const&, cv::Mat const&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0xebb): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0xede): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0xf2f): undefined reference to `cv::threshold(cv::_InputArray const&, cv::_OutputArray const&, double, double, int)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0xf74): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0xf97): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0xff2): undefined reference to `cv::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x103d): undefined reference to `cv::operator*(cv::Mat const&, double)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x105d): undefined reference to `cv::_InputArray::_InputArray(cv::MatExpr const&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x10b8): undefined reference to `cv::imwrite(std::string const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text+0x1110): undefined reference to `cv::waitKey(int)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text$_ZN2cv3MatD1Ev[__ZN2cv3MatD1Ev]+0x2d): undefined reference to `cv::fastFree(void*)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text$_ZN2cv3MataSERKS0_[__ZN2cv3MataSERKS0_]+0x102): undefined reference to `cv::Mat::copySize(cv::Mat const&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text$_ZN2cv3Mat7releaseEv[__ZN2cv3Mat7releaseEv]+0x3e): undefined reference to `cv::Mat::deallocate()' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text$_ZNK2cv3MatclENS_5RangeES1_[__ZNK2cv3MatclENS_5RangeES1_]+0x23): undefined reference to `cv::Mat::Mat(cv::Mat const&, cv::Range const&, cv::Range const&)' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text$_ZN2cv12_OutputArrayC1IdLi4ELi1EEERNS_4MatxIT_XT0_EXT1_EEE[__ZN2cv12_OutputArrayC1IdLi4ELi1EEERNS_4MatxIT_XT0_EXT1_EEE]+0x21): undefined reference to `vtable for cv::_OutputArray' 
C:\Users\HP\AppData\Local\Temp\ccraot3b.o:main.cpp:(.text$_ZN2cv11_InputArrayC2IdLi4ELi1EEERKNS_4MatxIT_XT0_EXT1_EEE[__ZN2cv11_InputArrayC2IdLi4ELi1EEERKNS_4MatxIT_XT0_EXT1_EEE]+0xe): undefined reference to `vtable for cv::_InputArray' 
collect2.exe: error: ld returned 1 exit status 
+0

Bitte fügen Sie die Compile-Ausgabe zur Frage hinzu! – hyde

Antwort

0

ich nicht Option -l verwendet haben, da es viele Bibliotheken sind und ich weiß nicht, wie all diese Bibliotheken zu verknüpfen (Verzeichnis) auf einmal.

Sie müssen die Option -l für jede Bibliothek verwenden, die verknüpft werden muss. Es gibt keine GCC-Befehlszeile Option, die verknüpfen, was auch immer Bibliotheken in diesem Verzeichnis sind. Die -L Option wie in Ihrem -LC:\opencv\build\x86\mingw\lib bedeutet das nicht. Es bedeutet Suche inC:\opencv\build\x86\mingw\libfür alle Bibliotheken, die durch die-lOption angefordert werden. Wenn Sie jedoch keine Bibliotheken mit der Option -l anfordern, wird keiner gesucht.

Wenn Sie Ihr Programm in Code :: Blocks, die Kompilierung und Verknüpfung Befehle erstellen, die in der Registerkarte (nicht die Nachrichten Erstellen tab) Build-Protokoll ausgedruckt werden ausgeführt werden. Wenn Sie also im Build-Protokoll nachsehen, werden Sie genau sehen, welche - -options an den Befehl compile und dann an den Befehl link übergeben werden müssen. Verwenden Sie genau die gleichen Optionen in der gleichen Reihenfolge an der Eingabeaufforderung, und Sie werden das Programm auf die gleiche Weise erstellen.

+0

Es funktionierte. Aber die Befehlszeile ist sehr groß. – sai

+0

@sai Um komplexe Software mit vielen Befehlen und langen Befehlszeilen zu erstellen, verwenden wir normalerweise ein Befehlszeilenprogramm höherer Ebene mit dem Namen ['make'] (https://www.gnu.org/software/make/). Hier ist ein [Tutorial über GCC und Make] (https://www3.ntu.edu.sg/home/ehchua/programming/cpp/gcc_make.html) Sie werden feststellen, dass ein Windows-Port von 'make' mit Ihrem mingw GCC kommt Verteilung.Es heißt 'mingw32-make.exe'. Code :: Blocks verwendet 'make' intern, um Ihre Projekte zu erstellen. Heutzutage ist ein noch höherwertiges Tool namens CMake sehr beliebt. 'CMake' verwendet auch' make', also ist es besser, wenn Sie 'make' zuerst verstehen. –

+0

Ok, ich werde mich darum kümmern. Danke – sai

0

Wahrscheinlich Problem ist, verwenden Sie Backslash in Pfaden. Wenn Sie mit MinGW oder Cygwin kompilieren (und ich nehme an, Sie sind), dann ist Backslash in dieser Shell ein Escape-Zeichen. Wenn Sie also einen einfachen Backslash haben möchten, müssen Sie ihm normalerweise entkommen: \\. Das ist jedoch nicht die richtige Lösung für Ihr Problem. Sie sollten normale Schrägstrich verwenden, /, in Pfade:

g++ -IC:/opencv/build/include -o main.exe main.cpp 

und

g++ -IC:/opencv/build/include -LC:/opencv/build/x86/mingw/lib -o main.exe main.cpp 
+0

Normaler Schrägstrich hat nicht funktioniert. Ich habe die Kompilierausgabe hinzugefügt. – sai