GemパッケージをインストールするときにC++11を指定する

bitcoinrb を mac で使うために leveldb-native を gem install しようとしたら,ビルドに失敗しました.どうやらオプションの指定が必要なようです.

エラー内容

原因は std=c++11 をオプションに指定していないことのようです.

エラー文の詳細は以下の通りです.

terminal

$ gem i leveldb-native
Building native extensions. This could take a while...
ERROR:  Error installing leveldb-native:
        ERROR: Failed to build gem native extension.

    current directory: /Users/mktia/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/leveldb-native-0.6/ext/leveldb-native
/Users/mktia/.rbenv/versions/2.6.3/bin/ruby -I /Users/mktia/.rbenv/versions/2.6.3/lib/ruby/2.6.0 -r ./siteconf20191226-1456-1crdg7e.rb extconf.rb
checking for -lleveldb... yes
creating Makefile

current directory: /Users/mktia/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/leveldb-native-0.6/ext/leveldb-native
make "DESTDIR=" clean

current directory: /Users/mktia/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/leveldb-native-0.6/ext/leveldb-native
make "DESTDIR="
compiling leveldb-native.cc
In file included from leveldb-native.cc:4:
In file included from /usr/local/include/leveldb/db.h:12:
In file included from /usr/local/include/leveldb/iterator.h:20:
/usr/local/include/leveldb/status.h:27:11: error: expected ';' at end of declaration list
  Status() noexcept : state_(nullptr) {}
          ^
/usr/local/include/leveldb/status.h:33:23: error: expected ';' at end of declaration list
  Status(Status&& rhs) noexcept : state_(rhs.state_) { rhs.state_ = nullptr; }
                      ^
/usr/local/include/leveldb/status.h:103:16: error: 'Status' is missing exception specification 'throw()'
inline Status::Status(const Status& rhs) {
               ^
/usr/local/include/leveldb/status.h:24:22: note: previous declaration is here
class LEVELDB_EXPORT Status {
                     ^
/usr/local/include/leveldb/status.h:115:48: error: expected function body after function declarator
inline Status& Status::operator=(Status&& rhs) noexcept {
                                               ^
4 errors generated.
make: *** [leveldb-native.o] Error 1

make failed, exit code 2

C++コンパイラをオプションで指定する

terminal

$ gem help install
Usage: gem install GEMNAME [GEMNAME ...] [options] -- --build-flags [options]

  Options:
        --platform PLATFORM          Specify the platform of gem to install
    -v, --version VERSION            Specify version of gem to install
        --[no-]prerelease            Allow prerelease versions of a gem
                                     to be installed. (Only for listed gems)
...

--build-flags のところで設定すればうまくいきそうです.

$ gem i leveldb-native -- --with-cxxflags=-std=c++11
Building native extensions with: '--with-cxxflags=-std=c++11'
This could take a while...
Successfully installed leveldb-native-0.6
Parsing documentation for leveldb-native-0.6
Done installing documentation for leveldb-native after 0 seconds
1 gem installed

終わり