使用g++编译器在Eclipse IDE中生成DLL类时出错
Error in making DLL class in Eclipse IDE with g++ compiler
我在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对象。
相关文章:
- 从DLL导出函数,LoadLibrary()需要用TEXT转换的字符串才能编译而不会出错
- 使用mingw遵循简单的c ++ DLL教程时出错
- 在 dll 中为 qLibrary 编译 qobject 时出错
- 从 Python 调用 Windows DLL 函数时出错
- 加载共享库时出错:JVM.dll
- 在 Windows 10 上使用 CZMQ 编译 dll 时出错
- 在Visual Studio中使用Cygwin编译的dll的库函数时出错
- 在Windows上使用GCC的链接时间优化构建wxWidgets DLL时出错
- 在DLL客户端中使用dllimport时出错
- 在C/C++中加载DLL时出错
- 使用 Visual Studio 2013 构建过剩 DLL 时出错
- 在 Windows 2008 上从 JNI 加载 dll 时出错
- 油.dll调用 - 访问被拒绝错误80020009出错
- 使用 libstdc++6.dll 运行代码时出错
- Qt创建者-当dll的标头出现在多个位置时出错
- Visual Studio链接器在尝试使用DLL中的静态库时出错(LNK2038、LNK2005)
- 在c++ dll中删除指针时出错
- C++ 与Dll沟通出错
- LNK1104.dll链接到 Visual Studio "invalid or corrupt file" 中的测试应用程序时出错
- 使用g++编译器在Eclipse IDE中生成DLL类时出错