c++ - 位于单个文件中的两个类的链接器错误 (LNK2019)

标签 c++ linker

我有两个类位于 ExtractMaximalStableRegion.h .他们是

    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;
    };

还有一个是

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是为了加快使用 TBB 的 ExtractM_StableRegion类(class)。

然后我有另一个cpp文件counting.cpp然后运行 ​​ExtractM_StableRegion_ParallelProcess分类为

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();

当我构建时,我遇到了我不理解的链接器错误

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)

链接器错误发生在方法 void compareWithSingleThread() 处使用 ExtractM_StableRegion()(objs[i].first, local, objs[i].second);

我也有对象ExtractM_StableRegion()(objs[i].first, local, objs[i].second);用于 void operator()(const tbb::blocked_range<tbb::size_t>& r)方法。为什么里面那个compareWithSingleThread()有错误,内部 operator()没有错误。 谢谢

最佳答案

链接器错误意味着编译器已终止且没有错误,但链接器无法为某些声明找到(函数、方法或符号的)定义 .问题是有时您必须猜测这是从哪里来的。

在您的情况下,我会执行以下操作:减少您的示例。注释掉错误消息中提到的每个(成员)变量和方法体。在您上面的原始帖子中,删除适当的行。这使得 SO 人员更容易理解哪里出了问题。它甚至可能引导您找到解决方案。

将方法体从 .cpp 文件移动到 .h 文件。这可能会提示您出了什么问题。或者重建 .cpp 文件。

检查各自的项目属性或 makefile 或其他。必须在某处指定什么链接到哪里什么以及如何。这可能不完整。

您可能会在 Stackoverflow 上找到其他提示,因为有很多很多关于链接器错误的问题,例如this one .

关于c++ - 位于单个文件中的两个类的链接器错误 (LNK2019),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30339630/

相关文章:

c++ - 查找链接时间瓶颈

c++ - 覆盖 SVML 的函数调用

C++通过重载更改成员函数的访问权限

c++ - C:将大数从字符串转换为以 n 为模的整数

c++ - 寻找可以解压缩 rar、7z、bz2、zip 等的 C++ 压缩库

c - ELF 文件中的程序头和节头

c++ - valgrind memcheck 给出消息 "in a rw- anonymous segment"

c++ - 如何在 Scons 中为具有相对路径的构建目标创建别名?

objective-c - Xcode - 替换类文件后链接错误 _OBJC_CLASS_$ _"className"

linux - 使用非标准路径编译 glib