可能重复:
C++:对静态类成员的未定义引用
记录器.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&);
};
记录器.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'