我的Eclipse IDE中有兩個項目。我的操作系統是Ubuntu。一個是應用程序項目,另一個是共享lib項目。我已經鏈接了link中討論的所有路徑和庫要求。但是當我調試時,我得到錯誤No source available for "0x0"
。當我訪問共享庫對象時,該錯誤發生在iOCR* pOCR = (iOCR*)create();
。我的鏈接有什麼問題? 附上我的共享庫代碼和應用程序代碼。訪問共享庫時沒有可用的源代碼錯誤
共用資料庫頭文件
#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
#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;
}
}
應用的main.cpp
#include <stdio.h>
#include "OCR_dll.h"
#define SUCCESS 0
#define FILE_ERROR 1
#define HTTP_ERROR 2
#define THREAD_ERROR 3
using namespace VIDEOANALYTICS_PLATFORM;
using namespace cv;
void *readImage(void *ptr);
void *postHTTP(void *ptr);
int main(int argc, char *argv[])
{
// on Linux, use "./myclass.so"
void* handle = dlopen("OCR.so", RTLD_LAZY);
iOCR* (*create)();
void (*destroy)(iOCR*);
create = (iOCR* (*)())dlsym(handle, "create_object");
destroy = (void (*)(iOCR*))dlsym(handle, "destroy_object");
iOCR* pOCR = (iOCR*)create();
if(pOCR){
destroy(pOCR);
}//if(pOCR)
dlclose(handle);
return 0;
}
我與objdumb選中並且輸出作爲遵循
[email protected]:~/workspace/OCR/Debug$ objdump -TC libOCR.so
libOCR.so: file format elf32-i386
DYNAMIC SYMBOL TABLE:
00000000 DF *UND* 00000000 GLIBC_2.1.3 __cxa_atexit
00000000 w D *UND* 00000000 __gmon_start__
00000000 w D *UND* 00000000 _Jv_RegisterClasses
00000000 DF *UND* 00000000 GLIBCXX_3.4 operator delete(void*)
00000000 DF *UND* 00000000 GLIBCXX_3.4 std::ios_base::Init::Init()
00000000 DF *UND* 00000000 GLIBCXX_3.4 std::ios_base::Init::~Init()
00000000 w D *UND* 00000000 _ITM_deregisterTMCloneTable
00000000 w D *UND* 00000000 _ITM_registerTMCloneTable
00000000 DO *UND* 00000000 CXXABI_1.3 vtable for __cxxabiv1::__class_type_info
00000000 DF *UND* 00000000 CXXABI_1.3 __cxa_pure_virtual
00000000 DF *UND* 00000000 GLIBCXX_3.4 operator new(unsigned int)
00000000 DO *UND* 00000000 CXXABI_1.3 vtable for __cxxabiv1::__si_class_type_info
00000000 w DF *UND* 00000000 GLIBC_2.1.3 __cxa_finalize
00000c95 g DF .text 00000020 Base destroy_object
00000dc4 w DF .text 0000001e Base VIDEOANALYTICS_PLATFORM::OCR::~OCR()
00000de4 g DF .fini 00000000 Base _fini
00000d94 w DF .text 00000030 Base VIDEOANALYTICS_PLATFORM::OCR::~OCR()
00000d94 w DF .text 00000030 Base VIDEOANALYTICS_PLATFORM::OCR::~OCR()
00000d4c w DF .text 0000001e Base VIDEOANALYTICS_PLATFORM::iOCR::~iOCR()
00000cc0 g DF .text 0000000a Base VIDEOANALYTICS_PLATFORM::OCR::textExtraction(cv::Mat&)
00000d78 w DF .text 0000001c Base VIDEOANALYTICS_PLATFORM::OCR::OCR()
00000aec g DF .init 00000000 Base _init
00000e40 w DO .rodata 00000020 Base typeinfo name for VIDEOANALYTICS_PLATFORM::OCR
00000d78 w DF .text 0000001c Base VIDEOANALYTICS_PLATFORM::OCR::OCR()
00003018 g D .bss 00000000 Base __bss_start
00000d26 w DF .text 00000025 Base VIDEOANALYTICS_PLATFORM::iOCR::~iOCR()
00000d6a w DF .text 0000000e Base VIDEOANALYTICS_PLATFORM::iOCR::iOCR()
00000d26 w DF .text 00000025 Base VIDEOANALYTICS_PLATFORM::iOCR::~iOCR()
0000301c g D .bss 00000000 Base _end
00000e18 w DO .rodata 00000018 Base vtable for VIDEOANALYTICS_PLATFORM::iOCR
00000e30 w DO .rodata 0000000c Base typeinfo for VIDEOANALYTICS_PLATFORM::OCR
00000d6a w DF .text 0000000e Base VIDEOANALYTICS_PLATFORM::iOCR::iOCR()
00000cb6 g DF .text 0000000a Base VIDEOANALYTICS_PLATFORM::OCR::preProcessing(cv::Mat&)
00000e00 w DO .rodata 00000018 Base vtable for VIDEOANALYTICS_PLATFORM::OCR
00003018 g D .data 00000000 Base _edata
00000e84 w DO .rodata 00000008 Base typeinfo for VIDEOANALYTICS_PLATFORM::iOCR
00000c6c g DF .text 00000029 Base create_object
00000e60 w DO .rodata 00000021 Base typeinfo name for VIDEOANALYTICS_PLATFORM::iOCR
在您的實際代碼中,您*有*有錯誤檢查?即確保'dlopen'或'dlsym'不會失敗? –
首先使用「objdump -TC OCR.so」列出OCR.so文件中的符號,並確保創建函數。你可能會缺少dll_export – sramij
@JoachimPileborg:如何檢查dlopen和dlsym不會失敗? – batuman