可能重复:
C++:未定义静态类成员的引用
Logger.h:
class Logger {
private:
Logger();
static void log(const string& tag, const string& msg, int level);
static Mutex mutex;
public:
static void fatal(const string&, const string&);
static void error(const string&, const string&);
static void warn(const string&, const string&);
static void debug(const string&, const string&);
static void info(const string&, const string&);
};
Logger.cpp:
#include "Logger.h"
#include <sstream>
ofstream Logger::archivoLog;
void Logger::warn(const string& tag, const string& msg){
Logger::mutex.lock();
log(tag, msg, LOG_WARN);
Logger::mutex.unlock();
}
编译时,我遇到了这个错误:
other/Logger.o: In function `Logger::warn(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
Logger.cpp:(.text+0x9): undefined reference to `Logger::mutex'
Logger.cpp:(.text+0x3b): undefined reference to `Logger::mutex'