Subscribed unsubscribe Subscribe Subscribe

Augmented Usamimi

it { is_expected.to be_blog.written_by(izumin5210) }

C++11でmsgpack-cを利用するときはMSGPACK_DISABLE_LEGACY_NILする

msgpack-c

error: expected unqualified-id typedef nil_t nil;

msgpack/msgpack-ccpp-2.0.0を利用. そのまま読み込むと以下のようなエラーを吐く.

In file included from
/path/to/msgpack-c/include/msgpack.hpp:18:
In file included from
/path/to/msgpack-c/include/msgpack/type.hpp:13:
In file included from
/path/to/msgpack-c/include/msgpack/adaptor/nil.hpp:13:
In file included from 
/path/to/msgpack-c/include/msgpack/adaptor/nil_decl.hpp:13:
/path/to/msgpack-c/include/msgpack/v1/adaptor/nil_decl.hpp:28:15: error: expected unqualified-id
typedef nil_t nil;
              ^
/usr/include/MacTypes.h:92:19: note: expanded from macro 'nil'
      #define nil nullptr
                  ^

環境は

  • OSX 10.10.5(Yosemite)
  • Apple LLVM version 7.0.2 (clang-700.1.81)

対処法

該当箇所見た感じ,MSGPACK_DISABLE_LEGACY_NILをつけてあげれば回避できそう.

#if !defined(MSGPACK_DISABLE_LEGACY_NIL)

typedef nil_t nil;

#endif // !defined(MSGPACK_DISABLE_LEGACY_NIL)

CMakeであれば以下のコードをCMakeLists.txtに追記してあげれば問題なく動く.

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMSGPACK_DISABLE_LEGACY_NIL")

雑記

v1/adaptor namespaceで怒られてるのがちょっと不思議なので,どっかでなんか間違ったのかもしれない.