Hey guys n gals,
I'm Ryan and this is my first post so a quick intro then on to the problem. I'm fresh outta uni and in my first programming job.
My background is in Java but the part of the project I am working on just now relies on OpenCV and hence C/C++ which I've been put in charge of because I used it at arms length in my disertation.
However I hardly had to touch the C code nevermind actually write my own functions in it so now I'm a bit stuck and in need of advice.
As the title suggests I'm having a problem with an undefind reference to 'cv::theRNG()' when trying to compile my project. I've spent the best part of the day trying to figure out what is going wrong but can't find it.
I know it is concerning the linking of libraries but I've linked everything I can think of and am no closer to solving the problem.
My setup is as follows:
Windows 7 on a Intel i5
Using Netbeans 7.0 for development
Using MinGW as my compiler (g++)
Using OpenCV2.3
Don't think there is any other system things you need to know but please ask if there is.
As for project setup with respect to OpenCV in Tools -> Options -> C/C++ -> Code Assistance -> C++ Compiler -> Include Directories I have C:\CCompiler\OpenCV2.3\include
In the project's properties I have:
Build -> C++ Compiler -> Include Directories ../../../../../CCompiler/OpenCV2.3/include
Additional Options '-Wl,--add-stdcall-alias'
Linker -> Additional Library Directories ../../../../../CCompiler/OpenCV2.3/lib
Libraries opencv_core230 opencv_highgui230 opencv_imgproc230 opencv_objdetect230 opencv_features2d (these are all dll files)
Additional Options '-Wl,--add-stdcall-alias'
And here is the code which is the convexhull example file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
/*
* File: convexhull.cpp
* Author: Ryan
*
* Created on 29 June 2011, 16:55
*/
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include <fstream>
#include <iostream>
using namespace cv;
using namespace std;
int main( int /*argc*/, char** /*argv*/ )
{
Mat img(500, 500, CV_8UC3);
RNG& rng = theRNG();
for(;;)
{
char key;
int i, count = (unsigned)rng%100 + 1;
vector<Point> points;
for( i = 0; i < count; i++ )
{
Point pt;
pt.x = rng.uniform(img.cols/4, img.cols*3/4);
pt.y = rng.uniform(img.rows/4, img.rows*3/4);
points.push_back(pt);
}
vector<int> hull;
convexHull(Mat(points), hull, true);
img = Scalar::all(0);
for( i = 0; i < count; i++ )
circle(img, points[i], 3, Scalar(0, 0, 255), CV_FILLED, CV_AA);
int hullcount = (int)hull.size();
Point pt0 = points[hull[hullcount-1]];
for( i = 0; i < hullcount; i++ )
{
Point pt = points[hull[i]];
line(img, pt0, pt, Scalar(0, 255, 0), 1, CV_AA);
pt0 = pt;
}
imshow("hull", img);
key = (char)waitKey();
if( key == 27 || key == 'q' || key == 'Q' ) // 'ESC'
break;
}
return 0;
}
|
and here is the actual errors I'm getting:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
"/bin/make" -f nbproject/Makefile-Facedetect.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/c/Users/Ryan/NetBeansProjects/Technabling/CppTutorials'
"/bin/make" -f nbproject/Makefile-Facedetect.mk dist/Facedetect/MinGW-Windows/cpptutorials.exe
make[2]: Entering directory `/c/Users/Ryan/NetBeansProjects/Technabling/CppTutorials'
mkdir -p build/Facedetect/MinGW-Windows
rm -f build/Facedetect/MinGW-Windows/handDetection.o.d
g++.exe -Wl,--add-stdcall-alias -c -g -I../../../../../CCompiler/OpenCV2.3/include -MMD -MP -MF build/Facedetect/MinGW-Windows/handDetection.o.d -o build/Facedetect/MinGW-Windows/handDetection.o handDetection.cpp
mkdir -p dist/Facedetect/MinGW-Windows
g++.exe -Wl,--add-stdcall-alias -Wl,--add-stdcall-alias -o dist/Facedetect/MinGW-Windows/cpptutorials build/Facedetect/MinGW-Windows/main.o build/Facedetect/MinGW-Windows/facedetect.o build/Facedetect/MinGW-Windows/convexhull.o build/Facedetect/MinGW-Windows/skindetect1.o build/Facedetect/MinGW-Windows/main2.o build/Facedetect/MinGW-Windows/handDetection.o -L../../../../../CCompiler/OpenCV2.3/lib -lopencv_core230 -lopencv_highgui230 -lopencv_imgproc230 -lopencv_objdetect230 -lopencv_features2d230
build/Facedetect/MinGW-Windows/convexhull.o: In function `main':
C:\Users\Ryan\NetBeansProjects\Technabling\CppTutorials/convexhull.cpp:22: undefined reference to `cv::theRNG()'
C:\Users\Ryan\NetBeansProjects\Technabling\CppTutorials/convexhull.cpp:41: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
C:\Users\Ryan\NetBeansProjects\Technabling\CppTutorials/convexhull.cpp:41: undefined reference to `cv::convexHull(cv::_InputArray const&, cv::_OutputArray const&, bool, bool)'
C:\Users\Ryan\NetBeansProjects\Technabling\CppTutorials/convexhull.cpp:43: undefined reference to `cv::Mat::operator=(cv::Scalar_<double> const&)'
C:\Users\Ryan\NetBeansProjects\Technabling\CppTutorials/convexhull.cpp:45: undefined reference to `cv::circle(cv::Mat&, cv::Point_<int>, int, cv::Scalar_<double> const&, int, int, int)'
C:\Users\Ryan\NetBeansProjects\Technabling\CppTutorials/convexhull.cpp:53: undefined reference to `cv::line(cv::Mat&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int)'
C:\Users\Ryan\NetBeansProjects\Technabling\CppTutorials/convexhull.cpp:57: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
C:\Users\Ryan\NetBeansProjects\Technabling\CppTutorials/convexhull.cpp:57: undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
C:\Users\Ryan\NetBeansProjects\Technabling\CppTutorials/convexhull.cpp:59: undefined reference to `cv::waitKey(int)'
build/Facedetect/MinGW-Windows/convexhull.o: In function `~Mat':
C:\Users\Ryan\NetBeansProjects\Technabling\CppTutorials/../../../../../CCompiler/OpenCV2.3/include/opencv2/core/mat.hpp:297: undefined reference to `cv::fastFree(void*)'
build/Facedetect/MinGW-Windows/convexhull.o:C:\Users\Ryan\NetBeansProjects\Technabling\CppTutorials/../../../../../CCompiler/OpenCV2.3/include/opencv2/core/mat.hpp:367: undefined reference to `cv::Mat::create(int, int const*, int)'
make[2]: Leaving directory `/c/Users/Ryan/NetBeansProjects/Technabling/CppTutorials'
build/Facedetect/MinGW-Windows/convexhull.o:C:\Users\Ryan\NetBeansProjects\Technabling\CppTutorials/../../../../../CCompiler/OpenCV2.3/include/opencv2/core/mat.hpp:381: undefined reference to `cv::Mat::deallocate()'
build/Facedetect/MinGW-Windows/convexhull.o: In function `Mat<cv::Point_<int> >':
make[1]: Leaving directory `/c/Users/Ryan/NetBeansProjects/Technabling/CppTutorials'
C:\Users\Ryan\NetBeansProjects\Technabling\CppTutorials/../../../../../CCompiler/OpenCV2.3/include/opencv2/core/mat.hpp:207: undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
C:\Users\Ryan\NetBeansProjects\Technabling\CppTutorials/../../../../../CCompiler/OpenCV2.3/include/opencv2/core/mat.hpp:207: undefined reference to `cv::Mat::copyTo(cv::_OutputArray const&) const'
build/Facedetect/MinGW-Windows/convexhull.o: In function `OutputArray<int>':
C:\Users\Ryan\NetBeansProjects\Technabling\CppTutorials/../../../../../CCompiler/OpenCV2.3/include/opencv2/core/mat.hpp:1110: undefined reference to `vtable for cv::_OutputArray'
build/Facedetect/MinGW-Windows/convexhull.o: In function `InputArray<int>':
C:\Users\Ryan\NetBeansProjects\Technabling\CppTutorials/../../../../../CCompiler/OpenCV2.3/include/opencv2/core/mat.hpp:1102: undefined reference to `vtable for cv::_InputArray'
collect2: ld returned 1 exit status
make[2]: *** [dist/Facedetect/MinGW-Windows/cpptutorials.exe] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 2s)
|
Ctrl + clicking on theRNG() takes me into the core.hpp file at this little peice of code
1 2
|
//! returns the thread-local Random number generator
CV_EXPORTS RNG& theRNG();
|
and doing the same there on RNG& takes me to the class decleration in the same file and finally ctrl + click on the construtor declatation takes me into the operations.hpp file and thats where the chain ends.
I tried adding operations.hpp in my #include list but it made no difference.
So if anyone can tell me where I'm going wrong, how to solve it and / or how to avoid it in future it would be a great help.
Thanks for reading, I'll be back to check for replies frequently and will post up the solution should I find it in the mean time.
Ryan