facebook / rocksdb

A library that provides an embeddable, persistent key-value store for fast storage.
http://rocksdb.org
GNU General Public License v2.0
27.85k stars 6.2k forks source link

Struggling to use run example program with RocksDB on MacOS #12743

Closed scrappyiron closed 4 weeks ago

scrappyiron commented 1 month ago

Expected behavior

On MacOS 14.2.1 (23C71) I should be able to compile and execute column_families_example.cc from the website (link) after installing RocksDB through brew.

Actual behavior

Compiling with g++ -o column_families_example column_families_example.cc -L/opt/homebrew/lib -lrocksdb -I/opt/homebrew/include gets me a lot of errors:

In file included from column_families_example.cc:9:
In file included from /opt/homebrew/include/rocksdb/db.h:20:
In file included from /opt/homebrew/include/rocksdb/attribute_groups.h:8:
In file included from /opt/homebrew/include/rocksdb/iterator_base.h:8:
/opt/homebrew/include/rocksdb/cleanable.h:19:27: warning: deleted function definitions are a C++11 extension [-Wc++11-extensions]
  Cleanable(Cleanable&) = delete;
                          ^
/opt/homebrew/include/rocksdb/cleanable.h:20:38: warning: deleted function definitions are a C++11 extension [-Wc++11-extensions]
  Cleanable& operator=(Cleanable&) = delete;
                                     ^
/opt/homebrew/include/rocksdb/cleanable.h:26:22: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
  Cleanable(Cleanable&&) noexcept;
                     ^
/opt/homebrew/include/rocksdb/cleanable.h:26:25: error: expected ';' at end of declaration list
  Cleanable(Cleanable&&) noexcept;
                        ^
                        ;
/opt/homebrew/include/rocksdb/cleanable.h:27:33: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
  Cleanable& operator=(Cleanable&&) noexcept;
                                ^
/opt/homebrew/include/rocksdb/cleanable.h:27:36: error: expected ';' at end of declaration list
  Cleanable& operator=(Cleanable&&) noexcept;
                                   ^
                                   ;
/opt/homebrew/include/rocksdb/cleanable.h:34:27: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
  using CleanupFunction = void (*)(void* arg1, void* arg2);
                          ^
/opt/homebrew/include/rocksdb/cleanable.h:95:40: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
  SharedCleanablePtr(SharedCleanablePtr&& from) noexcept;
                                       ^
/opt/homebrew/include/rocksdb/cleanable.h:95:48: error: expected ';' at end of declaration list
  SharedCleanablePtr(SharedCleanablePtr&& from) noexcept;
                                               ^
                                               ;
/opt/homebrew/include/rocksdb/cleanable.h:97:51: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
  SharedCleanablePtr& operator=(SharedCleanablePtr&& from) noexcept;
                                                  ^
/opt/homebrew/include/rocksdb/cleanable.h:97:59: error: expected ';' at end of declaration list
  SharedCleanablePtr& operator=(SharedCleanablePtr&& from) noexcept;
                                                          ^
                                                          ;
/opt/homebrew/include/rocksdb/cleanable.h:125:14: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
  Impl* ptr_ = nullptr;
             ^
In file included from column_families_example.cc:9:
In file included from /opt/homebrew/include/rocksdb/db.h:20:
In file included from /opt/homebrew/include/rocksdb/attribute_groups.h:8:
In file included from /opt/homebrew/include/rocksdb/iterator_base.h:9:
/opt/homebrew/include/rocksdb/slice.h:143:30: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
  PinnableSlice(PinnableSlice&& other);
                             ^
/opt/homebrew/include/rocksdb/slice.h:144:41: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
  PinnableSlice& operator=(PinnableSlice&& other);
                                        ^
/opt/homebrew/include/rocksdb/slice.h:147:35: warning: deleted function definitions are a C++11 extension [-Wc++11-extensions]
  PinnableSlice(PinnableSlice&) = delete;
                                  ^
/opt/homebrew/include/rocksdb/slice.h:148:46: warning: deleted function definitions are a C++11 extension [-Wc++11-extensions]
  PinnableSlice& operator=(PinnableSlice&) = delete;
                                             ^
/opt/homebrew/include/rocksdb/slice.h:221:16: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
  bool pinned_ = false;
               ^
In file included from column_families_example.cc:9:
In file included from /opt/homebrew/include/rocksdb/db.h:20:
In file included from /opt/homebrew/include/rocksdb/attribute_groups.h:8:
In file included from /opt/homebrew/include/rocksdb/iterator_base.h:10:
/opt/homebrew/include/rocksdb/status.h:59:16: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
  Status(Status&& s) noexcept;
               ^
/opt/homebrew/include/rocksdb/status.h:59:21: error: expected ';' at end of declaration list
  Status(Status&& s) noexcept;
                    ^
                    ;
/opt/homebrew/include/rocksdb/status.h:60:27: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
  Status& operator=(Status&& s) noexcept;
                          ^
/opt/homebrew/include/rocksdb/status.h:60:32: error: expected ';' at end of declaration list
  Status& operator=(Status&& s) noexcept;
                               ^
                               ;
/opt/homebrew/include/rocksdb/status.h:75:8: error: ISO C++ forbids forward references to 'enum' types
  enum Code : unsigned char {
       ^
/opt/homebrew/include/rocksdb/status.h:75:24: error: expected '(' for function-style cast or type construction
  enum Code : unsigned char {
              ~~~~~~~~ ^
/opt/homebrew/include/rocksdb/status.h:75:13: error: field has incomplete type 'enum Code'
  enum Code : unsigned char {
            ^
/opt/homebrew/include/rocksdb/status.h:75:8: note: forward declaration of 'rocksdb::Code'
  enum Code : unsigned char {
       ^
/opt/homebrew/include/rocksdb/status.h:100:8: error: ISO C++ forbids forward references to 'enum' types
  enum SubCode : unsigned char {
       ^
/opt/homebrew/include/rocksdb/status.h:100:27: error: expected '(' for function-style cast or type construction
  enum SubCode : unsigned char {
                 ~~~~~~~~ ^
/opt/homebrew/include/rocksdb/status.h:100:16: error: field has incomplete type 'enum SubCode'
  enum SubCode : unsigned char {
               ^
/opt/homebrew/include/rocksdb/status.h:100:8: note: forward declaration of 'rocksdb::SubCode'
  enum SubCode : unsigned char {
       ^
/opt/homebrew/include/rocksdb/status.h:126:8: error: ISO C++ forbids forward references to 'enum' types
  enum Severity : unsigned char {
       ^
/opt/homebrew/include/rocksdb/status.h:126:28: error: expected '(' for function-style cast or type construction
  enum Severity : unsigned char {
                  ~~~~~~~~ ^
/opt/homebrew/include/rocksdb/status.h:126:17: error: field has incomplete type 'enum Severity'
  enum Severity : unsigned char {
                ^
/opt/homebrew/include/rocksdb/status.h:126:8: note: forward declaration of 'rocksdb::Severity'
  enum Severity : unsigned char {
       ^
/opt/homebrew/include/rocksdb/status.h:158:28: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
  Status& UpdateIfOk(Status&& s) {
                           ^
/opt/homebrew/include/rocksdb/status.h:492:8: error: field has incomplete type 'Code'
  Code code_;
       ^
/opt/homebrew/include/rocksdb/status.h:75:8: note: forward declaration of 'rocksdb::Code'
  enum Code : unsigned char {
       ^
/opt/homebrew/include/rocksdb/status.h:493:11: error: field has incomplete type 'SubCode'
  SubCode subcode_;
          ^
/opt/homebrew/include/rocksdb/status.h:100:8: note: forward declaration of 'rocksdb::SubCode'
  enum SubCode : unsigned char {
       ^
/opt/homebrew/include/rocksdb/status.h:494:12: error: field has incomplete type 'Severity'
  Severity sev_;
           ^
/opt/homebrew/include/rocksdb/status.h:126:8: note: forward declaration of 'rocksdb::Severity'
  enum Severity : unsigned char {
       ^
/opt/homebrew/include/rocksdb/status.h:196:40: error: use of undeclared identifier 'kNone'
  static Status NotFound(SubCode msg = kNone) { return Status(kNotFound, msg); }
                                       ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
16 warnings and 20 errors generated.

Steps to reproduce the behavior

  1. Ran brew install rocksdb

  2. Confirmed brew installed rocksdb:

==> rocksdb: stable 9.2.1 (bottled), HEAD
Embeddable, persistent key-value store for fast storage
https://rocksdb.org/
Installed
/opt/homebrew/Cellar/rocksdb/9.2.1 (143 files, 37.6MB) *
  Poured from bottle using the formulae.brew.sh API on 2024-06-06 at 22:59:39
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/r/rocksdb.rb
License: GPL-2.0-only or Apache-2.0
==> Dependencies
Build: cmake ✘
Required: gflags ✔, lz4 ✔, snappy ✔, zstd ✔
==> Options
--HEAD
        Install HEAD version
==> Analytics
install: 515 (30 days), 1,573 (90 days), 5,869 (365 days)
install-on-request: 502 (30 days), 1,521 (90 days), 5,596 (365 days)
build-error: 8 (30 days)
  1. Run command to compile sample program: g++ -o column_families_example column_families_example.cc -L/opt/homebrew/lib -lrocksdb -I/opt/homebrew/include

Additional information

My g++ version is:

Apple clang version 15.0.0 (clang-1500.1.0.2.5)
Target: arm64-apple-darwin23.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
scrappyiron commented 1 month ago

Nevermind, I needed to compile with the -std=c++17 param like this:

g++ -o column_families_example column_families_example.cc -L/opt/homebrew/lib -lrocksdb -I/opt/homebrew/include -std=c++17

adamretter commented 4 weeks ago

@scrappyiron Yes indeed, your compiler opts were off. You might want to consider setting up a Makefile to handle stuff like that.