我想在VS2010中构建别人的代码。它在VS2005中构建得很好,但我需要升级它。模板宏的链接器错误:无法解析的外部符号
他们定义的宏作为在头如下:
#include <boost/scoped_ptr.hpp>
#include <boost/utility.hpp>
#include <boost/thread/once.hpp>
#define DEFINE_SINGLETON(name) boost::scoped_ptr<name> Singleton<name>::_instance
template<class T> class Singleton : private boost::noncopyable
{
public:
static T& instance()
{
boost::call_once(init, flag);
return *_instance;
}
static void init()
{
_instance.reset(new T());
}
protected:
Singleton() {}
~Singleton() {}
private:
static boost::scoped_ptr<T> _instance;
static boost::once_flag flag;
};
template<class T> boost::once_flag Singleton<T>::flag = BOOST_ONCE_INIT;
我已经成功地得到现在的代码来构建,但我获得了大量的连接错误的这个宏:
project1.lib(file1.obj) : error LNK2001: unresolved external symbol "private: static class boost::scoped_ptr<class ClassABC> Singleton<class ClassABC>::_instance" ([email protected][email protected]@@@@[email protected]@@@[email protected]@A)
宏的一个例子是使用(源文件):
#include "singleton.h"
DEFINE_SINGLETON(ClassABC);
我很新,来推动和也templat es(对不起),所以我无法理解为什么当VS2005中的所有链接都很好的时候出现这些错误。它值得一提的,是为了做升级,我们也必须提升我们的加速版本,所以这可能是一个因素 - 一些检查已经完成:
- 头文件包含在源文件
- 升压目录添加到include目录(下VC++迪尔斯inproperty页)
- 添加上去的lib目录到链接器 - >常规 - >附加库的依赖
有关信息,我在编译多线程调试DLL Win32的。
我花了大部分时间使用Google搜索无济于事,所以非常感谢任何帮助!
非常感谢:)
你使用'DEFINE_SINGLETON'宏地方? –
对不起,现在包含使用的宏的例子 – namford