求助:模板link2001 error的问题[visual studio 2008编译,ACE相关]
最近想在open diameter库的基础上做个简单的client demo,所以想在windows下编译这个库文件,但是opendiameter用到了部分ACE的接口,我在这里遇到的问题就是ACE_Singleton接口编译过去不,详细错误如下:
1> Creating library ./MyRelease\DiameterParser.lib and object ./MyRelease\DiameterParser.exp
1>aaa_avplist.obj : error LNK2001: unresolved external symbol "public: static class DiameterAvpTypeList_S * __cdecl ACE_Singleton<class DiameterAvpTypeList_S,class ACE_Recursive_Thread_Mutex>::instance(void)" (?instance@?$ACE_Singleton@VDiameterAvpTypeList_S@@VACE_Recursive_Thread_Mutex@@@@SAPAVDiameterAvpTypeList_S@@XZ)
1>aaa_error_status.obj : error LNK2001: unresolved external symbol "public: static class AAAMemoryManager * __cdecl ACE_Singleton<class AAAMemoryManager,class ACE_Recursive_Thread_Mutex>::instance(void)" (?instance@?$ACE_Singleton@VAAAMemoryManager@@VACE_Recursive_Thread_Mutex@@@@SAPAVAAAMemoryManager@@XZ)
1>./MyRelease\DiameterParser.dll : fatal error LNK1120: 2 unresolved externals
我贴出部分ACE_Singleton的代码下来:
/**
* @class ACE_Singleton
*
* @brief A Singleton Adapter uses the Adapter pattern to turn ordinary
* classes into Singletons optimized with the Double-Checked
* Locking optimization pattern.
*
* This implementation is a slight variation on the GoF
* Singleton pattern. In particular, a single
* <ACE_Singleton<TYPE, ACE_LOCK> > instance is allocated here,
* not a <TYPE> instance. The reason for this is to allow
* registration with the ACE_Object_Manager, so that the
* Singleton can be cleaned up when the process exits. For this
* scheme to work, a (static) cleanup() function must be
* provided. ACE_Singleton provides one so that TYPE doesn't
* need to.
* If you want to make sure that only the singleton instance of
* <T> is created, and that users cannot create their own
* instances of <T>, do the following to class <T>:
* (a) Make the constructor of <T> private (or protected)
* (b) Make Singleton a friend of <T>
* Here is an example:
* @verbatim
* class foo
* {
* friend class ACE_Singleton<foo, ACE_Null_Mutex>;
* private:
* foo () { cout << "foo constructed" << endl; }
* ~foo () { cout << "foo destroyed" << endl; }
* };
* typedef ACE_Singleton<foo, ACE_Null_Mutex> FOO;
* @endverbatim
*
* @note The best types to use for ACE_LOCK are
* ACE_Recursive_Thread_Mutex and ACE_Null_Mutex.
* ACE_Recursive_Thread_Mutex should be used in multi-threaded
* programs in which it is possible for more than one thread to
* access the <ACE_Singleton<TYPE, ACE_LOCK>> instance.
* ACE_Null_Mutex can be used otherwise. The reason that these
* types of locks are best has to do with their allocation by
* the ACE_Object_Manager. Single ACE_Recursive_Thread_Mutex
* and ACE_Null_Mutex instances are used for all ACE_Singleton
* instantiations. However, other types of locks are allocated
* per ACE_Singleton instantiation.
*/
template <class TYPE, class ACE_LOCK>
class ACE_Singleton : public ACE_Cleanup
{
public:
/// Global access point to the Singleton.
static TYPE *instance (void);
/// Cleanup method, used by @c ace_cleanup_destroyer to destroy the
/// ACE_Singleton.
virtual void cleanup (void *param = 0);
/// Explicitly delete the Singleton instance.
static void close (void);
/// Dump the state of the object.
static void dump (void);
protected:
/// Default constructor.
ACE_Singleton (void);
/// Contained instance.
TYPE instance_;
#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
/// Pointer to the Singleton (ACE_Cleanup) instance.
static ACE_Singleton<TYPE, ACE_LOCK> *singleton_;
#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
/// Get pointer to the Singleton instance.
static ACE_Singleton<TYPE, ACE_LOCK> *&instance_i (void);
};
在opendiameter中用到的部分:
class DiameterAvpList_S :
public AAAAvpList
{
friend class ACE_Singleton<DiameterAvpList_S, ACE_Recursive_Thread_Mutex>;
private:
DiameterAvpList_S();
virtual ~DiameterAvpList_S();
};
typedef ACE_Singleton<DiameterAvpList_S, ACE_Recursive_Thread_Mutex> DiameterAvpList;
我对这个问题的感觉:(不知道对不对,大家都提提自己的看法)
从error LNK2001: unresolved external symbol "public: static 应该是instence()这个function的问题....