google / glog

C++ implementation of the Google logging module
http://google.github.io/glog/
BSD 3-Clause "New" or "Revised" License
7.1k stars 2.07k forks source link

How can I build glog from source on Mac M1 or arm platform #1125

Open PengZai opened 2 months ago

PengZai commented 2 months ago

Hello, everyone. I git clone the source code and follow the instruction of offical website to build glog from the scratch. however, I failed in compiling process. it seems there are some syntactic error, but I guess it might be some misoperation by me. please help me.

what I've done basically is: 1)git clone https://github.com/google/glog.git 2)cmake -S . -B build -G "Unix Makefiles" 3)cmake --build build Then it abort, information is shown as following.

(base) pengzai@zhongzhipengs-MacBook-Pro glog % cmake -S . -B build -G "Unix Makefiles"

-- The CXX compiler identification is AppleClang 13.1.6.13160021
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Could NOT find GTest (missing: GTest_DIR)
CMake Warning at CMakeLists.txt:78 (find_package):
  By not providing "Findgflags.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "gflags", but
  CMake did not find one.

  Could not find a package configuration file provided by "gflags" (requested
  version 2.2.2) with any of the following names:

    gflagsConfig.cmake
    gflags-config.cmake

  Add the installation prefix of "gflags" to CMAKE_PREFIX_PATH or set
  "gflags_DIR" to a directory containing one of the above files.  If "gflags"
  provides a separate development package or SDK, be sure it has been
  installed.

-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Could NOT find Unwind (missing: Unwind_LIBRARY) 
-- Looking for C++ include dlfcn.h
-- Looking for C++ include dlfcn.h - found
-- Looking for C++ include elf.h
-- Looking for C++ include elf.h - not found
-- Looking for C++ include glob.h
-- Looking for C++ include glob.h - found
-- Looking for C++ include link.h
-- Looking for C++ include link.h - not found
-- Looking for C++ include pwd.h
-- Looking for C++ include pwd.h - found
-- Looking for C++ include sys/exec_elf.h
-- Looking for C++ include sys/exec_elf.h - not found
-- Looking for C++ include sys/syscall.h
-- Looking for C++ include sys/syscall.h - found
-- Looking for C++ include sys/time.h
-- Looking for C++ include sys/time.h - found
-- Looking for C++ include sys/types.h
-- Looking for C++ include sys/types.h - found
-- Looking for C++ include sys/utsname.h
-- Looking for C++ include sys/utsname.h - found
-- Looking for C++ include sys/wait.h
-- Looking for C++ include sys/wait.h - found
-- Looking for C++ include syscall.h
-- Looking for C++ include syscall.h - not found
-- Looking for C++ include syslog.h
-- Looking for C++ include syslog.h - found
-- Looking for C++ include ucontext.h
-- Looking for C++ include ucontext.h - not found
-- Looking for C++ include unistd.h
-- Looking for C++ include unistd.h - found
-- Looking for C++ include stdint.h
-- Looking for C++ include stdint.h - found
-- Looking for C++ include stddef.h
-- Looking for C++ include stddef.h - found
-- Check size of mode_t
-- Check size of mode_t - done
-- Check size of ssize_t
-- Check size of ssize_t - done
-- Looking for dladdr
-- Looking for dladdr - found
-- Looking for fcntl
-- Looking for fcntl - found
-- Looking for posix_fadvise
-- Looking for posix_fadvise - not found
-- Looking for pread
-- Looking for pread - found
-- Looking for pwrite
-- Looking for pwrite - found
-- Looking for sigaction
-- Looking for sigaction - found
-- Looking for sigaltstack
-- Looking for sigaltstack - found
-- Looking for backtrace
-- Looking for backtrace - found
-- Looking for backtrace_symbols
-- Looking for backtrace_symbols - found
-- Looking for _chsize_s
-- Looking for _chsize_s - not found
-- Looking for UnDecorateSymbolName
-- Looking for UnDecorateSymbolName - not found
-- Looking for abi::__cxa_demangle
-- Looking for abi::__cxa_demangle - found
-- Looking for __argv
-- Looking for __argv - not found
-- Looking for getprogname
-- Looking for getprogname - found
-- Looking for program_invocation_short_name
-- Looking for program_invocation_short_name - not found
-- Performing Test HAVE___PROGNAME
-- Performing Test HAVE___PROGNAME - Failed
-- Looking for gmtime_r
-- Looking for gmtime_r - found
-- Looking for localtime_r
-- Looking for localtime_r - found
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/pengzai/vscode_project/glog/build
(base) pengzai@zhongzhipengs-MacBook-Pro glog % cmake --build build
[  2%] Building CXX object CMakeFiles/glog_internal.dir/src/demangle.cc.o
[  5%] Building CXX object CMakeFiles/glog_internal.dir/src/flags.cc.o
[  8%] Building CXX object CMakeFiles/glog_internal.dir/src/logging.cc.o
[ 11%] Building CXX object CMakeFiles/glog_internal.dir/src/raw_logging.cc.o
[ 13%] Building CXX object CMakeFiles/glog_internal.dir/src/signalhandler.cc.o
/Users/pengzai/vscode_project/glog/src/signalhandler.cc:246:11: warning: Symbolize functionality is not available for target platform: stack dump will contain empty frames. [-W#pragma-messages]
pragma message( \
          ^
1 warning generated.
[ 16%] Building CXX object CMakeFiles/glog_internal.dir/src/stacktrace.cc.o
[ 19%] Building CXX object CMakeFiles/glog_internal.dir/src/symbolize.cc.o
[ 22%] Building CXX object CMakeFiles/glog_internal.dir/src/utilities.cc.o
[ 25%] Building CXX object CMakeFiles/glog_internal.dir/src/vlog_is_on.cc.o
[ 25%] Built target glog_internal
[ 27%] Generating CMakeFiles/glog.cc
[ 30%] Building CXX object CMakeFiles/glog.dir/CMakeFiles/glog.cc.o
[ 33%] Linking CXX shared library libglog.dylib
[ 33%] Built target glog
[ 36%] Building CXX object CMakeFiles/logging_unittest.dir/src/logging_unittest.cc.o
In file included from /Users/pengzai/vscode_project/glog/src/logging_unittest.cc:61:
In file included from /Users/pengzai/vscode_project/glog/src/base/commandlineflags.h:63:
In file included from /Users/pengzai/vscode_project/glog/src/glog/logging.h:63:
In file included from /Users/pengzai/vscode_project/glog/src/glog/flags.h:49:
/Users/pengzai/vscode_project/glog/src/glog/types.h:40:15: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using int32 = std::int32_t;
              ^
/Users/pengzai/vscode_project/glog/src/glog/types.h:41:16: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using uint32 = std::uint32_t;
               ^
/Users/pengzai/vscode_project/glog/src/glog/types.h:42:15: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using int64 = std::int64_t;
              ^
/Users/pengzai/vscode_project/glog/src/glog/types.h:43:16: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using uint64 = std::uint64_t;
               ^
In file included from /Users/pengzai/vscode_project/glog/src/logging_unittest.cc:61:
In file included from /Users/pengzai/vscode_project/glog/src/base/commandlineflags.h:63:
In file included from /Users/pengzai/vscode_project/glog/src/glog/logging.h:77:
/Users/pengzai/vscode_project/glog/src/glog/log_severity.h:89:1: error: unknown type name 'constexpr'
constexpr int NUM_SEVERITIES = 4;
^
In file included from /Users/pengzai/vscode_project/glog/src/logging_unittest.cc:61:
In file included from /Users/pengzai/vscode_project/glog/src/base/commandlineflags.h:63:
/Users/pengzai/vscode_project/glog/src/glog/logging.h:86:60: error: expected ';' at end of declaration list
  const std::chrono::system_clock::time_point& when() const noexcept {
                                                           ^
                                                           ;
/Users/pengzai/vscode_project/glog/src/glog/logging.h:473:33: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using PrefixFormatterCallback = void (*)(std::ostream&, const LogMessage&,
                                ^
/Users/pengzai/vscode_project/glog/src/glog/logging.h:563:3: warning: explicit conversion functions are a C++11 extension [-Wc++11-extensions]
  explicit operator bool() const noexcept {
  ^~~~~~~~
/Users/pengzai/vscode_project/glog/src/glog/logging.h:563:33: error: expected ';' at end of declaration list
  explicit operator bool() const noexcept {
                                ^
                                ;
/Users/pengzai/vscode_project/glog/src/glog/logging.h:562:53: error: member initializer 'str_' does not name a non-static data member or base class
  CheckOpString(std::unique_ptr<std::string> str) : str_(std::move(str)) {}
                                                    ^~~~~~~~~~~~~~~~~~~~
/Users/pengzai/vscode_project/glog/src/glog/logging.h:713:23: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using _Check_string = std::string;
                      ^
/Users/pengzai/vscode_project/glog/src/glog/logging.h:983:22: error: unknown type name 'constexpr'
GLOG_INLINE_VARIABLE constexpr Counter_t COUNTER{};
                     ^
/Users/pengzai/vscode_project/glog/src/glog/logging.h:983:41: error: expected ';' after top level declarator
GLOG_INLINE_VARIABLE constexpr Counter_t COUNTER{};
                                        ^
                                        ;
/Users/pengzai/vscode_project/glog/src/glog/logging.h:1210:24: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
    LogStream(LogStream&& other) noexcept
                       ^
/Users/pengzai/vscode_project/glog/src/glog/logging.h:1210:33: error: expected ';' at end of declaration list
    LogStream(LogStream&& other) noexcept
                                ^
                                ;
/Users/pengzai/vscode_project/glog/src/glog/logging.h:1235:46: warning: deleted function definitions are a C++11 extension [-Wc++11-extensions]
    LogStream& operator=(const LogStream&) = delete;
                                             ^
/Users/pengzai/vscode_project/glog/src/glog/logging.h:1289:16: error: expected ';' at end of declaration list
  ~LogMessage() noexcept(false);
               ^
               ;
/Users/pengzai/vscode_project/glog/src/glog/logging.h:1306:4: error: expected expression
  [[noreturn]] static void Fail();
   ^
/Users/pengzai/vscode_project/glog/src/glog/logging.h:1306:16: error: expected member name or ';' after declaration specifiers
  [[noreturn]] static void Fail();
               ^
/Users/pengzai/vscode_project/glog/src/glog/logging.h:1315:31: error: expected ';' at end of declaration list
  LogSeverity severity() const noexcept;
                              ^
                              ;
/Users/pengzai/vscode_project/glog/src/glog/logging.h:1316:19: error: expected ';' at end of declaration list
  int line() const noexcept;
                  ^
                  ;
/Users/pengzai/vscode_project/glog/src/glog/logging.h:1317:43: error: expected ';' at end of declaration list
  const std::thread::id& thread_id() const noexcept;
                                          ^
                                          ;
/Users/pengzai/vscode_project/glog/src/glog/logging.h:1318:31: error: expected ';' at end of declaration list
  const char* fullname() const noexcept;
                              ^
                              ;
/Users/pengzai/vscode_project/glog/src/glog/logging.h:1319:31: error: expected ';' at end of declaration list
  const char* basename() const noexcept;
                              ^
                              ;
/Users/pengzai/vscode_project/glog/src/glog/logging.h:1320:37: error: expected ';' at end of declaration list
  const LogMessageTime& time() const noexcept;
                                    ^
                                    ;
/Users/pengzai/vscode_project/glog/src/glog/logging.h:1322:35: warning: deleted function definitions are a C++11 extension [-Wc++11-extensions]
  LogMessage(const LogMessage&) = delete;
                                  ^
/Users/pengzai/vscode_project/glog/src/glog/logging.h:1323:46: warning: deleted function definitions are a C++11 extension [-Wc++11-extensions]
  LogMessage& operator=(const LogMessage&) = delete;
                                             ^
/Users/pengzai/vscode_project/glog/src/glog/logging.h:1361:4: error: expected expression
  [[noreturn]] ~LogMessageFatal() noexcept(false);
   ^
/Users/pengzai/vscode_project/glog/src/glog/logging.h:1361:34: error: expected ';' at end of declaration list
  [[noreturn]] ~LogMessageFatal() noexcept(false);
                                 ^
                                 ;
/Users/pengzai/vscode_project/glog/src/glog/logging.h:1412:64: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
T CheckNotNull(const char* file, int line, const char* names, T&& t) {
                                                               ^
/Users/pengzai/vscode_project/glog/src/glog/logging.h:1414:38: error: no member named 'make_unique' in namespace 'std'
    LogMessageFatal(file, line, std::make_unique<std::string>(names));
                                ~~~~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
12 warnings and 20 errors generated.
make[2]: *** [CMakeFiles/logging_unittest.dir/src/logging_unittest.cc.o] Error 1
make[1]: *** [CMakeFiles/logging_unittest.dir/all] Error 2
make: *** [all] Error 2
(base) pengzai@zhongzhipengs-MacBook-Pro glog % 
PengZai commented 2 months ago

this offical instruction works in ubuntu20.04 x86_64 platform but it doesn't in Mac M1 or arm platform.

sergiud commented 2 months ago

Your setup seems to be broken because the compiler doesn't even recognize C++11 syntax while latest glog requires C++14.