2015-06-22 46 views
0

我在Eclipse中使用g ++編譯器導出一個dll類。我的操作系統是Ubuntu,該應用程序將在Ubuntu操作系統中運行。我創建了一個共享項目。使用g ++編譯器在Eclipse IDE中創建DLL類的錯誤

我有編譯錯誤的

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_ */ 

回答

0

我得到了解決。在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 

一類。然後,我們可以創建的共享庫的對象。