我正在尝试使用boost来创建插件,但是在使其无法正常工作时遇到了一些困难,我关注的是boost.org上的this tutorial。 我正在使用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;
};
这是我的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)此声明没有存储类或类型说明符
为什么我会从boost中收到此消息,我该如何解决?
答案 0 :(得分:0)
只需将其移到名称空间之外,似乎无法使用拆包:
#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
)