我正在尝试使用 G3Log(Google 记录器的一个版本 - glog)在静态库中进行一些记录。在我尝试将该静态库引入 C++/CLI 托管包装器之前,一切都运行良好。当我这样做时,我遇到了可怕的问题:
error C1189: #error : <mutex> is not supported when compiling with /clr or /clr:pure.
问题是接收器的回调函数需要 g2::LogMessageMover,为此,我必须带回头文件。那么,我怎样才能封装 glog.hpp 标头,以免它对 C++/CLI 应用程序可见?
这是我尝试过的,但我被困在接收器的回调中。
class Log {
private:
void *log_;
void *trace_;
void *logworker;
public:
std::string LogPath = "";
std::string LogFile = "Log.txt";
std::string TraceFile = "Trace.txt";
Log();
void Initialize(std::string log_path, std::string log_file, std::string trace_file);
// How to define this and hide the implementation??
void LogMessage( g2::LogMessageMover message );
// How to define this and hide the implementation??
void TraceMessage( g2::LogMessageMover message);
virtual ~Log();
};
这是CPP文件:
#include "include/g2logworker.hpp"
#include "include/g2log.hpp"
Log::Log() {
logworker = (void *)(g2::LogWorker::createWithNoSink().get());
};
void Log::Initialize(std::string log_path, std::string log_file, std::string trace_file) {
auto worker = static_cast<g2::LogWorker *>(logworker);
auto loghandle = worker->addSink(std::make_unique<Log>(), &Log::LogMessage);
log_ = (void *) loghandle.get();
auto tracehandle = worker->addSink(std::make_unique<Log>(), &Log::TraceMessage);
trace_ = (void *) tracehandle.get();
g2::initializeLogging(worker);
};
void Log::LogMessage( g2::LogMessageMover message) {
fprintf(stderr, "Got the log message");
};
void Log::TraceMessage( g2::LogMessageMover message) {
fprintf(stderr, "Got the trace message");
};