首页 > 解决方案 > 错误的文件描述符 boost dll

问题描述

主文件

#include <boost/dll.hpp> 
#include <iostream>
# include "abstract.h"

using namespace boost::dll;

int main(int argc, char* argv[]) {


     boost::filesystem::path lib_path("/home/deven/Music/dllimport");    
    boost::shared_ptr<my_api_interface> plugin;   
    std::cout << "Loading the plugin" << std::endl;

    plugin = import<my_api_interface>(          
        lib_path / "libctest.so.1.0",                     
        "plugin",                                       
        load_mode::append_decorations              
    );

    plugin->cal(10,20);
}

摘要.h

# ifndef ABSTRACT_H
# define ABSTRACT_H
class   my_api_interface
{

    public:
     my_api_interface();

    virtual void cal(int a ,int b) = 0;

    ~my_api_interface();

};
# endif

库文件

# include "abstract.h"
# include <boost/dll.hpp>
# ifndef LIB_H
# define LIB_H

namespace my_name
{
    class actual_api : public my_api_interface
    {
        public:
        actual_api();
        void cal(int ,int ) ;
        ~actual_api();
    };

    extern "C" BOOST_SYMBOL_EXPORT actual_api plugin;
    actual_api plugin;
}
# endif

库文件

# include "lib.h"
# include <iostream>

using std::endl;

using std::cout;
void my_name::actual_api:: cal(int a,int b)
{
    cout << a+ b << endl;
}

抛出未定义符号的实例后调用错误终止:_ZN7my_name10actual_apiD1Ev):错误的文件描述符已中止(核心转储)我在linux中使用-fpic创建.so,然后使用boost.dll加载.so。我收到了这个糟糕的 fd 错误

标签: c++boost

解决方案


推荐阅读