使用g++编译器在Eclipse IDE中生成DLL类时出错

Error in making DLL class in Eclipse IDE with g++ compiler

本文关键字:DLL 出错 编译器 g++ Eclipse IDE 使用      更新时间:2023-10-16

我在Eclipse中做了一个项目,用g++编译器导出一个dll类。我的操作系统是Ubuntu,应用程序将在Ubuntu操作系统中运行。我创建了一个共享项目。

我将错误编译为

expected constructor, destructor, or type conversion before ‘(’ token   OCR_dll.h   /OCR    line 19 C/C++ Problem

#define DLLCLASS __declspec(dllexport)发生的错误以及如何解决该错误。非常感谢。

我的dll代码头文件是

OCR_dll.h
#ifndef OCR_DLL_H_
#define OCR_DLL_H_
#include <stdio.h>
#include <opencv/cv.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <tesseract/baseapi.h>
#include <iostream>
#include "Define.h"
#ifdef EXPORT
#define DLLCLASS __declspec(dllexport)
#else
#define DLLCLASS __declspec(dllimport)
#endif
using namespace cv;
#ifdef __cplusplus
extern "C" {
#endif
namespace VIDEOANALYTICS_PLATFORM {
    class iOCR{
        public:
            virtual ~iOCR(){}
            virtual int preProcessing(Mat &img) = 0;
            virtual int textExtraction(Mat &img) = 0;
    };
    class OCR : public iOCR{
        public:
            OCR(){}
            ~OCR(){ ; }
            int preProcessing(Mat &img);
            int textExtraction(Mat &img);
        private:

    };
    extern "C"{ DLLCLASS iOCR* __stdcall  createOCRObject(); };
}
#ifdef __cplusplus
}
#endif
#endif /* OCR_DLL_H_ */

我得到了解决方案。在Linux环境中,dll被称为共享库。我创建共享库的方式是

Headerfile  
    #ifndef OCR_DLL_H_   
    #define OCR_DLL_H_
    #include <opencv/cv.h>
    #include <opencv2/highgui/highgui.hpp>
    #include <opencv2/imgproc/imgproc.hpp>
    #include <tesseract/baseapi.h>
    #include <iostream>
    #include "Define.h"

    using namespace cv;

    namespace VIDEOANALYTICS_PLATFORM {
        class iOCR{
            public:
                virtual ~iOCR(){}
                virtual int preProcessing(Mat &img) = 0;
                virtual int textExtraction(Mat &img) = 0;
        };
        class OCR : public iOCR{
            public:
                OCR(){}
                ~OCR(){ ; }
                int preProcessing(Mat &img);
                int textExtraction(Mat &img);
            private:

        };

    }

    #endif /* OCR_DLL_H_ */
CPP file
#include "OCR_dll.h"

namespace VIDEOANALYTICS_PLATFORM {
    extern "C" iOCR* create_object(){
        iOCR *p = new OCR();
        return p;
    }
    extern "C" void destroy_object( iOCR* object )
    {
      delete object;
    }
    int OCR::preProcessing(Mat &img){

        return SUCCESS;
    }
    int OCR::textExtraction(Mat &img){

        return SUCCESS;
    }
}
MAKEFILE
g++ -fPIC -shared OCR_dll.cpp -o OCR_dll.so

然后我们可以为一个类创建共享的lib对象。