GNOME Bugzilla – Bug 618931
Error if gi18n-lib.h happens to come after config.h
Last modified: 2018-05-22 13:35:32 UTC
I encounter an error if I use _() for localization. The problem depends on how Vala chooses to order #include lines in the generated C code. Apparently the order of "using" lines doesn't matter. In file included from default/postler/postler-bureau.c:20:0: /usr/include/glib-2.0/glib/gi18n-lib.h:29:2: Fehler: #error You must define GETTEXT_PACKAGE before including gi18n-lib.h. Did you forget to include config.h? To elaborate, I define the symbol like this: [CCode (cprefix = "", lower_case_prefix = "", cheader_filename = "config.h")] namespace Config { [CCode (cname = "GETTEXT_PACKAGE")] public const string GETTEXT_PACKAGE; My workaround to influence the #include order is right now this: const string GETTEXT_PACKAGE_CONTENT = Config.GETTEXT_PACKAGE; So the Vala compiler should actually ensure that the #includes are ordered correctly. In #vala the suggested solution was to introduce a 'crequire_symbol' so that Vala could know that it has to include config.h first.
These have been the proposed solutions on IRC, rectify if I'm wrong: 1) a require_csymbol="GETTEXT_PACKAGE" on methods with cheader_filename="gi18n.h", then a Vala declaration is needed 2) an argument to specify what header to include before gi18n.h, i.e. CCode (cheader_filename="config.h,gi18n.h") or something like that, no Vala declaration needed 3) an argument CCode (before_include="gi18n.h") const string GETTEXT_PACKAGE, Vala declaration needed Cons: - 1 and 3 require Vala declaration, but usually keeps GETTEXT_PACKAGE or such in C headers. - 1 needs the whole code to be traversed (only once of course) to find a symbol whose cname is require_csymbol - 2 forces the final programmer to create a config.h, in autoconf one could even create a package-config.h instead - 3 first gcc error, then the programmer as to guess or read FAQ on how to fix the problem Pros: - 1 makes valac generate a understandable error before getting to gcc - 2 does not need a Vala declaration - 3 faster than 1, no code traversing needed
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/98.