I am trying to use G3Log (a version of the Google logger - glog) to do some logging within a static library. All works very well until I try to bring that static library into a C++/CLI managed wrapper. When I do this, I get the dreaded issue:
error C1189: #error : <mutex> is not supported when compiling with /clr or /clr:pure.
The problem, is that the callback functions for the sink require g2::LogMessageMover, and to do that, I have to bring back in the header file. So, how can I encapsulate the glog.hpp header so as not to make it visible to the C++/CLI application?
Here is what I tried, but I am stuck on the callback for the sink.
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();
};
Here is the CPP file:
#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");
};