GNOME Bugzilla – Bug 744473
including <gio/gio.h> causes "redefinition of typedef" compile warning
Last modified: 2017-09-11 15:26:06 UTC
#include <gio/gio.h> int main() { return 0; } On mac, compiling above code with latest xcode causes typedef compiler warning as following; In file included from /mypath/install/include/glib-2.0/gio/gio.h:163: /mypath/install/include/glib-2.0/gio/glistmodel.h:36:21: warning: redefinition of typedef 'GListModel' is a C11 feature [-Wtypedef-redefinition] G_DECLARE_INTERFACE(GListModel, g_list_model, G, LIST_MODEL, GObject) ^ /mypath/install/include/glib-2.0/gobject/gtype.h:1559:35: note: expanded from macro 'G_DECLARE_INTERFACE' typedef struct _##ModuleObjName ModuleObjName... ^ /mypath/install/include/glib-2.0/gio/giotypes.h:64:47: note: previous definition is here typedef struct _GListModel GListModel; Here is my gcc version information; $ gcc --version Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn) Target: x86_64-apple-darwin14.1.0 Thread model: posix
Redefinition of typedef is illegal in C. Do we need to put a definition check in G_DECLARE_FINAL_TYPE ?
(In reply to Young Han Lee from comment #1) > Redefinition of typedef is illegal in C. no, it's not illegal in C11 and it has been a GCC extension before that.
(In reply to Emmanuele Bassi (:ebassi) from comment #2) > no, it's not illegal in C11 and it has been a GCC extension before that. You're right. It would be better to use -Wno-typedef-redefinition option in this case. Thanks.
I did not close the bug report on purpose, in case there's something GLib can do to avoid the warning.
*** Bug 744485 has been marked as a duplicate of this bug. ***
glib 2.43.91 cannot be compiled on OS X 10.6 or earlier (which use Apple's gcc 4.2.1 or earlier) because: In file included from ../../gio/gio.h:164, from kqueue-exclusions.c:26: ../../gio/glistmodel.h:36: error: redefinition of typedef 'GListModel' ../../gio/giotypes.h:64: error: previous declaration of 'GListModel' was here In file included from ../../gio/gio.h:165, from kqueue-exclusions.c:26: ../../gio/gliststore.h:36: error: redefinition of typedef 'GListStore' ../../gio/giotypes.h:65: error: previous declaration of 'GListStore' was here
*** Bug 746694 has been marked as a duplicate of this bug. ***
FWIW, same error happens on OpenBSD.
Just to extend on my former comment. As is, GLib is now impossible to build on OpenBSD (gcc 4.2.1). If I use another compiler,
Oops, pressed a key to fast. So as I was saying... As is, GLib is now impossible to build by default on OpenBSD (gcc 4.2.1). If I use a newer compiler (e.g. gcc 4.8) then I can build it *but* anything depending on GLib/gio will not be able to build unless I also use a newer compiler to build them. Since the default compiler on OpenBSD is gcc 4.2.1, this is not really acceptable for us to use an external gcc to build 1000 packages from our ports tree. Could the GLib team revisit this change so that it works with not-too-modern compilers? Thanks.
Issue fixed with this GLib commit: 4a292721bcf2943bfc05c6a1c859992f28e3efec