求助动态链接库链接问题!
有一个类声明如下:
class DLLOPT DefaultLog {
public:
DefaultLog() { }
~DefaultLog() { }
/**
* Initialize the default logger with the given logging implementation.
*
* @param logger
* an AgentLog instance to be used as default logger. A previously
* set logger will be deleted.
*/
static void init(AgentLog* logger)
{ if (instance) delete instance; instance = logger; }
/**
* Return the default logger.
*
* @return
* a pointer to an AgentLog instance.
*/
static AgentLog* log()
{ if (!instance) init(new AgentLogImpl()); return instance; }
/**
* Create a new log entry or reuse an existing one.
*
* @param type
* the type of the log entry as bitwise or of log class and level.
*/
static void create_log_entry(unsigned char t)
{ if (!entry) { entry = log()->create_log_entry(t); entry->init();} }
/**
* Return the current log entry. If there is none, an ERROR_LOG entry
* with level 1 will be created.
*
* @return
* a pointer to a LogEntry instance.
*/
static LogEntry* log_entry()
{ if (!entry) create_log_entry(ERROR_LOG | 1); return entry; }
/**
* Delete current log entry.
*/
static void delete_log_entry()
{ if (entry) delete entry; entry = 0; }
protected:
static AgentLog* instance;
static LogEntry* entry;
};
我和其他一些文件编译生成lib和dll,在使用过程中出现如下问题:
error LNK2001: unresolved external symbol "protected: static class AgentLog * DefaultLog::instance" (?instance@DefaultLog@@1PAVAgentLog@@A)
error LNK2001: unresolved external symbol "protected: static class LogEntry * DefaultLog::entry" (?entry@DefaultLog@@1PAVLogEntry@@A)
开始我怀疑没有正确导出这两个成员变量,于是我使用dumpbin导出dll发现里面有如下项:
2796 AEB 0043AC74 ?instance@DefaultLog@@1PAVAgentLog@@A
2127 84E 0043AC78 ?entry@DefaultLog@@1PAVLogEntry@@A
VC环境的设置应该没有问题,因为如果我在setting里去掉对应的lib文件,将会出现更多的链接错误。
不知道问题出在哪里,谢谢各位指点!