简体   繁体   English

使用BOOST_DLL_ALIAS时了解并修复此错误消息

[英]Understanding and fixing this error Message when using BOOST_DLL_ALIAS

I am trying to create plugins using boost and am having some difficulty getting it to work, I am following this tutorial from boost.org. 我正在尝试使用boost创建插件,但要使其正常工作有些困难,我正在关注boost.org上的本教程 I am using boost 1_70 compiled with Visual Studio 2015. This is my code for the interface IFoo.h: 我正在使用通过Visual Studio 2015编译的boost 1_70。这是我的接口IFoo.h的代码:

#include <string>
#include <boost/config.hpp>
//Pluggin Interface for Puffs
class BOOST_SYMBOL_VISIBLE IFoo {
    public:
    //returns size of Foo
    virtual size_t Size() = 0;
    //get single byte from foo
    virtual unsigned char getByte(unsigned long loc) = 0;
};

This is my code for Foo.h: 这是我的Foo.h代码:

#include <boost/dll/alias.hpp>
#include <boost/make_shared.hpp> 
#include "IFoo.h"

namespace someSpace{
class Foo: public IFoo
{
    size_t FooSize;
    unsigned char * someData;
    Foo(std::string someString);
public:
    ~Foo();
    size_t Size();
    unsigned char getByte(unsigned long byteLoc);

    //Factory method
    static boost::shared_ptr<IFoo> create(std::string fooName);
};

BOOST_DLL_ALIAS(
    someSpace::Foo::create, //<-- this function is exported with...
    load_foo                 //<-- this alias
)
}

And here is the code for foo.cpp if it is needed: 如果需要,这是foo.cpp的代码:

#include "Foo.h"
namespace someSpace {
     Foo::Foo()std::string fooData)
     {
         strcpy(someData, fooData.c_str());
     }
     size_t Foo::size()
     {
         return FooSize;
     }
     unsigned char Foo::getByte(unsigned long byteLoc)
     {
          return someData[byteLoc % FooSize); 
     }

     static boost::shared_ptr<IFoo> Foo::create(std::string fooName)
     {
          return boost::shared_ptr<IFoo> ( new Foo(fooName) );
     }
}

I am getting an error from BOOST_DLL_ALIAS() which reads 我从BOOST_DLL_ALIAS()读取错误

#define BOOST_DLL_ALIAS(FunctionOrVar, AliasName) this declaration has no storage class or type specifier #define BOOST_DLL_ALIAS(FunctionOrVar,AliasName)此声明没有存储类或类型说明符

Why am I getting this message from boost and how can I fix it? 为什么我会从boost获得此消息,我该如何解决?

Just move it outside the namespace, it seems not to work with demangling: 只是将其移至名称空间之外,似乎无法进行拆装:

#include <boost/dll/alias.hpp>
#include <boost/make_shared.hpp> 
#include "IFoo.h"

namespace someSpace{
class Foo: public IFoo
{
    size_t FooSize;
    unsigned char * someData;
    Foo(std::string someString);
public:
    ~Foo();
    size_t Size();
    unsigned char getByte(unsigned long byteLoc);

    //Factory method
    static boost::shared_ptr<IFoo> create(std::string fooName);
};
}

BOOST_DLL_ALIAS(
    someSpace::Foo::create, //<-- this function is exported with...
    load_foo                 //<-- this alias
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM