2

I have two classes located in ExtractMaximalStableRegion.h. They are

    class ExtractM_StableRegion 
    {
        public:
            //! the full constructor
            ExtractM_StableRegion(int _delta = 5, int _min_area = 60, int _max_area = 14400,
                double _max_variation = 0.25, double _min_diversity = .2,
                int _max_evolution = 200, double _area_threshold = 1.01,
                double _min_margin = 0.003, int _edge_blur_size = 5);

            //! the operator that extracts the MSERs from the image or the specific part of it
            void operator()(const Mat& image, CV_OUT vector<vector<Point> >& msers, const Mat& mask = Mat());
            //AlgorithmInfo* info() const;

        protected:


            int delta;
            int minArea;
            int maxArea;
            double maxVariation;
            double minDiversity;
            int maxEvolution;
            double areaThreshold;
            double minMargin;
            int edgeBlurSize;
    };

Another one is

class ExtractM_StableRegion_ParallelProcess{

        private:
            vector<pair<Mat, Mat>> objs;
            vector<vector<Point>> msers;
        public:
            ~ExtractM_StableRegion_ParallelProcess(){
                if (!objs.empty())
                {
                    objs.clear();
                    vector<pair<Mat, Mat>>().swap(objs);//check these Mat is released
                }
                if (!objs.empty())
                {
                    msers.clear();
                    vector<vector<Point> >().swap(msers);
                }

            }

            void operator()(const tbb::blocked_range<tbb::size_t>& r) {
                for (tbb::size_t i = r.begin(); i != r.end(); ++i)
                {
                    ExtractM_StableRegion()(objs[i].first, msers, objs[i].second);
                }
            }

            ExtractM_StableRegion_ParallelProcess(vector<pair<Mat, Mat>> objs_) : objs(objs_){}

            ExtractM_StableRegion_ParallelProcess(ExtractM_StableRegion_ParallelProcess& x, tbb::split) : objs(x.objs), msers(x.msers){}

            void join(ExtractM_StableRegion_ParallelProcess& y)
            {
                for (vector<vector<Point> >::iterator it = y.msers.begin(); it != y.msers.end(); ++it)
                    msers.push_back(*it);   
                vector< vector<Point> > local;//check local is released
                ExtractM_StableRegion()(objs[0].first, local, objs[0].second);
            }

            void compareWithSingleThread(){
                for (int i = 0; i < objs.size(); ++i)
                {
                    vector< vector<Point> > local;//check local is released
                    ExtractM_StableRegion()(objs[i].first, local, objs[i].second);
                    for (vector<vector<Point> >::iterator it = local.begin(); it != local.end(); ++it)
                        msers.push_back(*it);
                }
                return;
            }

            vector<vector<Point> > getMSER_Regions(){
                return msers;
            }
    };

ExtractM_StableRegion_ParallelProcess is to speed up using TBB for ExtractM_StableRegion class.

Then I have another cpp file counting.cpp and run ExtractM_StableRegion_ParallelProcess class as

ExtractM_StableRegion_ParallelProcess *ep = new ExtractM_StableRegion_ParallelProcess(objs);
//tbb::parallel_reduce(blocked_range<size_t>(0, numObj), *ep, auto_partitioner());//simple_partitioner()
    ep->compareWithSingleThread();

When I build, I have linker error that I don't understand as

Counting.obj : error LNK2019: unresolved external symbol "public: __cdecl VIDEOANALYTICS_PLATFORM::ExtractM_StableRegion::ExtractM_StableRegion(int,int,int,double,double,int,double,double,int)" (??0ExtractM_StableRegion@VIDEOANALYTICS_PLATFORM@@QEAA@HHHNNHNNH@Z) referenced in function "public: void __cdecl VIDEOANALYTICS_PLATFORM::ExtractM_StableRegion_ParallelProcess::compareWithSingleThread(void)" (?compareWithSingleThread@ExtractM_StableRegion_ParallelProcess@VIDEOANALYTICS_PLATFORM@@QEAAXXZ)
1>Counting.obj : error LNK2019: unresolved external symbol "public: void __cdecl VIDEOANALYTICS_PLATFORM::ExtractM_StableRegion::operator()(class cv::Mat const &,class std::vector<class std::vector<class cv::Point_<int>,class std::allocator<class cv::Point_<int> > >,class std::allocator<class std::vector<class cv::Point_<int>,class std::allocator<class cv::Point_<int> > > > > &,class cv::Mat const &)" (??RExtractM_StableRegion@VIDEOANALYTICS_PLATFORM@@QEAAXAEBVMat@cv@@AEAV?$vector@V?$vector@V?$Point_@H@cv@@V?$allocator@V?$Point_@H@cv@@@std@@@std@@V?$allocator@V?$vector@V?$Point_@H@cv@@V?$allocator@V?$Point_@H@cv@@@std@@@std@@@2@@std@@0@Z) referenced in function "public: void __cdecl VIDEOANALYTICS_PLATFORM::ExtractM_StableRegion_ParallelProcess::compareWithSingleThread(void)" (?compareWithSingleThread@ExtractM_StableRegion_ParallelProcess@VIDEOANALYTICS_PLATFORM@@QEAAXXZ)

The linker error is happening at method void compareWithSingleThread() for using ExtractM_StableRegion()(objs[i].first, local, objs[i].second);

I also have object ExtractM_StableRegion()(objs[i].first, local, objs[i].second);used in void operator()(const tbb::blocked_range<tbb::size_t>& r) method. Why the one inside compareWithSingleThread() has error and inside operator() doesn't have error. Thanks

batuman
  • 7,066
  • 26
  • 107
  • 229
  • 1
    You are missing the implementations of `ExtractM_StableRegion()` and `void ExtractM_StableRegion::operator()(...)`. – Axalo May 20 '15 at 03:24
  • No they are in ExtractMaximalStableRegion.cpp file. I didn't include them as I am worried for too much code in the description. – batuman May 20 '15 at 03:58

1 Answers1

1

A linker error means that the compiler had terminated without errors but the linker is unable to find the definition (of a function, method, or symbol) for some declaration . The problem is that sometimes you have to guess where this comes from.

In your case I'd do the following: Reduce your example. Comment out every (member) variable and method body except for those mentioned in the error message. In your original post above remove the appropriate lines. This makes it easier for SO people to understand what is going wrong. It may even lead you to the solution.

Move the method bodies from the .cpp file to the .h file. This might give you a hint on what's going wrong. Or rebuild the .cpp file.

Check the respective project properties or makefile or whatever. Somewhere it has to be specified what is linked where and to what and how. This is maybe incomplete.

You may find other hints here at Stackoverflow because there are many, many questions about linker errors, e.g. this one.

Community
  • 1
  • 1
TobiMcNamobi
  • 4,687
  • 3
  • 33
  • 52
  • Yes linker can't find the definition. I have cpp file for ExtractMaximalStableRegion.cpp. I initially those constructors ExtractM_StableRegion(........) and operator() are defined in the cpp file. Now I shifted to ExtractMaximalStableRegion.h file and linker can see. A little bit weird for why linker can't see those definitions when they are in the cpp file. – batuman May 21 '15 at 06:58