g++でgdbmを使うと error: non-local function uses anonymous type
現象
g++ にて gdbm を使おうとすると、下記のエラーになる
$ cat c.cpp #includevoid foo(GDBM_FILE *p) { } $ g++ c.cpp c.cpp:3: error: non-local function ‘void foo( **)’ uses anonymous type
環境
$ g++ --version g++ (GCC) 4.4.6 20110731 (Red Hat 4.4.6-3) Copyright (C) 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ cat /etc/redhat-release CentOS release 6.2 (Final)
原因
C++ では、無名構造体へのポインタは使えないため。gdbm-1.10にて修正された模様。
$ grep GDBM_FILE /usr/include/gdbm.h typedef struct {int dummy[10];} *GDBM_FILE; $ grep GDBM_FILE gdbm-1.10/src/gdbm.h typedef struct gdbm_file_info *GDBM_FILE;
対処
- gdbm-1.10にバージョンアップ
- gdbm.hをローカルにコピーして下記のパッチを当てる(無保証)
- /usr/include/gdbm.h 2010-11-11 17:21:30.000000000 +0900 +++ gdbm.h 2012-06-03 21:30:43.066350424 +0900 @@ -60,7 +60,8 @@ /* The file information header. This is good enough for most applications. */ -typedef struct {int dummy[10];} *GDBM_FILE; +struct gdbm_dummy_info { int dummy[10]; }; +typedef struct gdb_dummy_info *GDBM_FILE; /* Determine if the C(++) compiler requires complete function prototype */ #ifndef __P