KeithBrown39423 / Hexdump

The alternative cross-platform hex dumping utility
MIT License
16 stars 0 forks source link

[Bug] Unable to compile on MacOS Sonoma #29

Closed ZackeryRSmith closed 4 months ago

ZackeryRSmith commented 5 months ago

Describe the bug I am unable to compile Hexdump's [release branch]() on my MacOS Sonoma laptop.

❯ make
mkdir -p bin
g++ -Wall -Werror -Wpedantic  -O3 -I lib -I include src/hexdump.cpp src/log.cpp 
In file included from src/hexdump.cpp:5:
In file included from include/hexdump.h:12:
include/hex_errno.h:17:23: error: no newline at end of file [-Werror,-Wnewline-e
#endif // _HEX_ERRNO_H
                      ^
In file included from src/hexdump.cpp:5:
In file included from include/hexdump.h:14:
lib/cxxopts.hpp:113:8: error: unknown type name 'constexpr'
static constexpr struct {
       ^
lib/cxxopts.hpp:281:16: error: alias declarations are a C++11 extension [-Werror
using String = std::string;
               ^
lib/cxxopts.hpp:285:16: error: rvalue references are a C++11 extension [-Werror,
toLocalString(T&& t)
               ^
lib/cxxopts.hpp:320:15: error: rvalue references are a C++11 extension [-Werror,
toUTF8String(T&& t)
              ^
lib/cxxopts.hpp:362:22: error: defaulted function definitions are a C++11 extens
  virtual ~Value() = default;
                     ^
lib/cxxopts.hpp:416:3: error: exception specification of overriding function is 
  what() const noexcept override
  ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__excepto
  virtual const char* what() const _NOEXCEPT;
                      ^
In file included from src/hexdump.cpp:5:
In file included from include/hexdump.h:14:
lib/cxxopts.hpp:416:15: error: expected ';' at end of declaration list
  what() const noexcept override
              ^
              ;
lib/cxxopts.hpp:410:5: error: member initializer 'm_message' does not name a non
  : m_message(std::move(message))
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/cxxopts.hpp:560:3: error: '_Static_assert' is a C11 extension [-Werror,-Wc11
  static_assert(std::is_base_of<std::exception, T>::value,
  ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__confige
#    define static_assert(...) _Static_assert(__VA_ARGS__)
                               ^
In file included from src/hexdump.cpp:5:
In file included from include/hexdump.h:14:
lib/cxxopts.hpp:566:10: error: expected '(' for function-style cast or type cons
  throw T{text};
        ~^
lib/cxxopts.hpp:576:21: error: alias declarations are a C++11 extension [-Werror
using OptionNames = std::vector<std::string>;
                    ^
lib/cxxopts.hpp:584:24: error: default member initializer for non-static data me
  std::string negative = "";
                       ^
lib/cxxopts.hpp:585:24: error: default member initializer for non-static data me
  std::string base     = "";
                       ^
lib/cxxopts.hpp:586:24: error: default member initializer for non-static data me
  std::string value    = "";
                       ^
lib/cxxopts.hpp:589:25: error: default member initializer for non-static data me
  std::string arg_name  = "";
                        ^
lib/cxxopts.hpp:590:25: error: default member initializer for non-static data me
  bool        grouping  = false;
                        ^
lib/cxxopts.hpp:591:25: error: default member initializer for non-static data me
  bool        set_value = false;
                        ^
lib/cxxopts.hpp:592:25: error: default member initializer for non-static data me
  std::string value     = "";
                        ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
In file included from src/log.cpp:1:
In file included from include/hexdump.h:12:
include/hex_errno.h:17:23: error: no newline at end of file [-Werror,-Wnewline-e
#endif // _HEX_ERRNO_H
                      ^
In file included from src/log.cpp:1:
In file included from include/hexdump.h:14:
lib/cxxopts.hpp:113:8: error: unknown type name 'constexpr'
static constexpr struct {
       ^
lib/cxxopts.hpp:281:16: error: alias declarations are a C++11 extension [-Werror
using String = std::string;
               ^
lib/cxxopts.hpp:285:16: error: rvalue references are a C++11 extension [-Werror,
toLocalString(T&& t)
               ^
lib/cxxopts.hpp:320:15: error: rvalue references are a C++11 extension [-Werror,
toUTF8String(T&& t)
              ^
lib/cxxopts.hpp:362:22: error: defaulted function definitions are a C++11 extens
  virtual ~Value() = default;
                     ^
lib/cxxopts.hpp:416:3: error: exception specification of overriding function is 
  what() const noexcept override
  ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__excepto
  virtual const char* what() const _NOEXCEPT;
                      ^
In file included from src/log.cpp:1:
In file included from include/hexdump.h:14:
lib/cxxopts.hpp:416:15: error: expected ';' at end of declaration list
  what() const noexcept override
              ^
              ;
lib/cxxopts.hpp:410:5: error: member initializer 'm_message' does not name a non
  : m_message(std::move(message))
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/cxxopts.hpp:560:3: error: '_Static_assert' is a C11 extension [-Werror,-Wc11
  static_assert(std::is_base_of<std::exception, T>::value,
  ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__confige
#    define static_assert(...) _Static_assert(__VA_ARGS__)
                               ^
In file included from src/log.cpp:1:
In file included from include/hexdump.h:14:
lib/cxxopts.hpp:566:10: error: expected '(' for function-style cast or type cons
  throw T{text};
        ~^
lib/cxxopts.hpp:576:21: error: alias declarations are a C++11 extension [-Werror
using OptionNames = std::vector<std::string>;
                    ^
lib/cxxopts.hpp:584:24: error: default member initializer for non-static data me
  std::string negative = "";
                       ^
lib/cxxopts.hpp:585:24: error: default member initializer for non-static data me
  std::string base     = "";
                       ^
lib/cxxopts.hpp:586:24: error: default member initializer for non-static data me
  std::string value    = "";
                       ^
lib/cxxopts.hpp:589:25: error: default member initializer for non-static data me
  std::string arg_name  = "";
                        ^
lib/cxxopts.hpp:590:25: error: default member initializer for non-static data me
  bool        grouping  = false;
                        ^
lib/cxxopts.hpp:591:25: error: default member initializer for non-static data me
  bool        set_value = false;
                        ^
lib/cxxopts.hpp:592:25: error: default member initializer for non-static data me
  std::string value     = "";
                        ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [build] Error 1

To Reproduce Steps to reproduce the behavior:

  1. git clone git clone https://github.com/KeithBrown39423/Hexdump
  2. cd Hexdump
  3. make

Expected behavior A successful compiled Hexdump binary

Desktop:

KeithBrown39423 commented 5 months ago

With the exception of the no newline at end of file error, this probably would belong as an issue in the cxxopt repo

ZackeryRSmith commented 5 months ago

This actually is a Hexdump issue. Or it may be directly related with how g++ works. If you read the error messages it talks about how x feature is a C++11 extension or a c++17 extension. This means you must compile with the flag -std=c++17. Doing this gives separate issues though:

❯ make
mkdir -p bin
g++ -Wall -Werror -Wpedantic -std=c++17  -O3 -I lib -I include src/hexdump.cpp src/log.cpp -o bin/hex
src/hexdump.cpp:212:5: error: 'sprintf' is deprecated: This function is provided for compatibility re
    sprintf(offset_str, "%08X", offset);
    ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h:180:1: note: 'sprintf' has be
__deprecated_msg("This function is provided for compatibility reasons only.  Due to security concerns"
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:218:48: note: expanded fr
        #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
                                                      ^
src/hexdump.cpp:225:13: error: 'sprintf' is deprecated: This function is provided for compatibility r
            sprintf(byte_str, "%02X", buffer[i]);
            ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h:180:1: note: 'sprintf' has be
__deprecated_msg("This function is provided for compatibility reasons only.  Due to security concerns"
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:218:48: note: expanded fr
        #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
                                                      ^
2 errors generated.
make: *** [build] Error 1
ZackeryRSmith commented 4 months ago

New Zig version compiles with Zig 0.12.0 on MacOS Sonoma