我正在尝试使用 boost 创建插件,但在让它工作时遇到了一些困难,我正在关注 this tutorial来自 boost.org。 我正在使用用 Visual Studio 2015 编译的 boost 1_70。 这是我的接口(interface) 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;
};
这是我的 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
)
}
如果需要,这里是 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) );
}
}
我收到来自 BOOST_DLL_ALIAS() 的错误信息
#define BOOST_DLL_ALIAS(FunctionOrVar, AliasName) this declaration has no storage class or type specifier
为什么我会从 boost 收到这条消息,我该如何解决?
最佳答案
只需将它移出命名空间,它似乎不适用于 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
)
关于c++ - 使用 BOOST_DLL_ALIAS 时了解并修复此错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55939581/