c++通过代码动态加载库文件并调用库里的类和方法

首先需要先在库文件的工程定义extern “c”

/**
 * 因在开发阶段发现tensorflow 与 海康的sdk 存在冲突,在还没有找到更好的解决方法时,使用动态加载so库的方法解决,
 * 以下是为了使动态加载能找到函数标识符而加入的接口函数,通过函数调用FrameProcessHelper类
*/
extern “C”{
    FrameProcessHelper * create(std::string names_file,std::string cfg_file,std::string weights_file);
//    void detect_and_track(cv::Mat org_frame,FrameProcessHelper & helper);
    std::vector<bbox_t> get_detect_track_result(cv::Mat & org_frame,FrameProcessHelper & helper);
    void draw_frame(cv::Mat & org_frame,bbox_t & dets, ais_data & ais,std::string & ocr_result,double & speed,FrameProcessHelper & helper);
}
CMakeList 定义输出的类型
add_library(new_detect SHARED
xxxx.cpp
xxxx.h
c++动态调用库文件代码截图说明