fmtlog
fmtlog copied to clipboard
Failure to build on MacOS
Pulled "main" today and included in a C++ program which I am compiling on macOS.
I had 2 issues, the first is as follows:
fmtlog/fmtlog.h:101:28: error: expected ';' at end of declaration list
static void preallocate() FMT_NOEXCEPT;
^
;
I rectified this adding #define FMT_NOEXCEPT
to my source file prior to #include <fmtlog/fmtlog.h>
I now have:
#define FMTLOG_HEADER_ONLY
#define FMT_HEADER_ONLY
#define FMT_NOEXCEPT
#include <fmtlog/fmtlog.h>
#include <fmt/format.h>
The second issue is with macOS where the functionsyscall
is deprecated:
fmtlog/fmtlog-inl.h:294:44: warning: 'syscall' is deprecated: first deprecated in macOS 10.12 - syscall(2) is unsupported; please switch to a supported interface. For SYS_kdebug_trace use kdebug_signpost(). [-Wdeprecated-declarations]
uint32_t tid = static_cast<uint32_t>(::syscall(SYS_gettid));
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:746:6: note: 'syscall' has been explicitly marked deprecated here
int syscall(int, ...);
^
1 warning generated.
I have patched locally by adding the following:
diff --git a/fmtlog-inl.h b/fmtlog-inl.h
index 9d85e51..34e1c11 100644
--- a/fmtlog-inl.h
+++ b/fmtlog-inl.h
@@ -38,6 +38,10 @@ SOFTWARE.
#include <unistd.h>
#endif
+#ifdef __APPLE__
+#include <pthread.h>
+#endif
+
namespace {
void fmtlogEmptyFun(void*) {
}
@@ -290,6 +294,9 @@ public:
fmtlog::threadBuffer = new fmtlog::ThreadBuffer();
#ifdef _WIN32
uint32_t tid = static_cast<uint32_t>(::GetCurrentThreadId());
+#elif __APPLE__
+ uint64_t tid = 0;
+ pthread_threadid_np(nullptr, &tid);
#else
uint32_t tid = static_cast<uint32_t>(::syscall(SYS_gettid));
#endif
FMT_NOEXCEPT issue has been fixed.