試験運用中なLinux備忘録・旧記事

はてなダイアリーで公開していた2007年5月-2015年3月の記事を保存しています。

GLSOF(lsofのGUI)のビルドエラーについてとその対処

GLSOF(glsof.sourceforge.net)をソースからインストールしようとしたところ

x86_64-pc-linux-gnu-gcc (中略) -c about.c
about.c: In function 'on_info_clicked':
about.c:33: error: initializer element is not constant
about.c:33: error: (near initialization for 'authors[0]')
about.c:34: error: initializer element is not constant
about.c:34: error: (near initialization for 'authors[1]')
about.c:35: error: initializer element is not constant
about.c:35: error: (near initialization for 'authors[2]')
about.c:36: error: initializer element is not constant
about.c:36: error: (near initialization for 'authors[3]')
about.c:40: error: initializer element is not constant
make[2]: *** [about.o] Error 1
make[2]: Leaving directory `/var/tmp/portage/x11-misc/glsof-0.10.0_alpha4/work/glsof-0.10.0-pre-alpha4/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/var/tmp/portage/x11-misc/glsof-0.10.0_alpha4/work/glsof-0.10.0-pre-alpha4'
make: *** [all-recursive-am] Error 2
 *
 * ERROR: x11-misc/glsof-0.10.0_alpha4 failed.
 * Call stack:
 *               ebuild.sh, line   49:  Called src_compile
 *             environment, line  718:  Called gnome2_src_compile
 *             environment, line  643:  Called die
 * The specific snippet of code:
 *       emake || die "compile failure"
 *  The die message:
 *   compile failure

のようになってビルドに失敗した。
ソースの該当部分を見たところ、幸い、些細な部分の「書き方」に関する問題(後述)だったため、修正して正常にビルドすることができた。
[任意]ファイル名: glsof-0.10.0_alpha4-nls.patch

diff -ur glsof-0.10.0-pre-alpha4.orig/src/about.c glsof-0.10.0-pre-alpha4/src/about.c
--- glsof-0.10.0-pre-alpha4.orig/src/about.c
+++ glsof-0.10.0-pre-alpha4/src/about.c
@@ -30,21 +30,21 @@
     GdkPixbuf *pixbuf;
 
     static const gchar *authors[] = {
-	_("Main coder:\nDaniele <danielef@users.sourceforge.net>"),
-	_("\nDocumentation:\nDaniele <danielef@users.sourceforge.net>"),
-	_("\nGraphics:\nDaniele <danielef@users.sourceforge.net>"),
-	_("\nVarious:\nN. Shmyrev <nshmyrev@yandex.ru>"),
+	N_("Main coder:\nDaniele <danielef@users.sourceforge.net>"),
+	N_("\nDocumentation:\nDaniele <danielef@users.sourceforge.net>"),
+	N_("\nGraphics:\nDaniele <danielef@users.sourceforge.net>"),
+	N_("\nVarious:\nN. Shmyrev <nshmyrev@yandex.ru>"),
 	NULL
     };
 
-    static const gchar *translators = _("Italian:\nDaniele <danielef@users.sourceforge.net>\n\nRussian:\nN. Shmyrev <nshmyrev@yandex.ru>");
+    static const gchar *translators = N_("Italian:\nDaniele <danielef@users.sourceforge.net>\n\nRussian:\nN. Shmyrev <nshmyrev@yandex.ru>");
 
     pixbuf = gdk_pixbuf_new_from_file(PIXMAPS_PATH "glsof-logo.png", NULL);
 
     window4 = gnome_about_new(_("GLSOF"), _("0.10.0 pre-alpha 4"),
 			      _("Copyleft \xc2\xa9 2006 Daniele\n"),
-			      _("GNOME GUI for LSOF."), authors, NULL,
-			      translators, pixbuf);
+			      _("GNOME GUI for LSOF."), _(authors), NULL,
+			      _(translators), pixbuf);
 
     gtk_widget_show(window4);
 }
diff -ur glsof-0.10.0-pre-alpha4.orig/src/query_editor.c glsof-0.10.0-pre-alpha4/src/query_editor.c
--- glsof-0.10.0-pre-alpha4.orig/src/query_editor.c
+++ glsof-0.10.0-pre-alpha4/src/query_editor.c
@@ -61,7 +61,7 @@
 /* extern */
 query_editor pf;
 
-static const gchar *titles_dialog [] = { _("Processes"), _("Network"), _("ID/Login Name"), _("File Descriptors"), _("Directories"), _("PID"), _("GPID") };
+static const gchar *titles_dialog [] = { N_("Processes"), N_("Network"), N_("ID/Login Name"), N_("File Descriptors"), N_("Directories"), N_("PID"), N_("GPID") };
 			
 			
 /*******************************************************************************
@@ -411,9 +411,9 @@
 	guint i;
 	/* no strings for PROCESSES and NETWORK */
 	static const gchar *warnings[] = {NULL, NULL, \
-		_("\"ID/Login name\" list is selected but empty."), _("\"File Descriptors\" list is selected but empty."), \
-		_("\"Directories\" list is selected but empty."), _("\"PID\" list is selected but empty."), \
-		_("\"GPID\" list is selected but empty.") };
+		N_("\"ID/Login name\" list is selected but empty."), N_("\"File Descriptors\" list is selected but empty."), \
+		N_("\"Directories\" list is selected but empty."), N_("\"PID\" list is selected but empty."), \
+		N_("\"GPID\" list is selected but empty.") };
 	
 	if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (pf.cb_active[PROCESSES])) && (g_slist_length (pf.list[PROCESSES]) == 0) )
 	{
@@ -425,7 +425,7 @@
 	{
 		if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (pf.cb_active[i])) && (g_slist_length (pf.list[i]) == 0) )
 		{
-			WARNING_DIALOG (warnings[i], pf.window);
+			WARNING_DIALOG (_(warnings[i]), pf.window);
 			return TRUE;
 		}
 	}
@@ -818,7 +818,7 @@
 	
 	selected = pf.selected;
 
-    GtkWidget *dialog = gtk_dialog_new_with_buttons (titles_dialog[selected],
+    GtkWidget *dialog = gtk_dialog_new_with_buttons (_(titles_dialog[selected]),
                                                   GTK_WINDOW(pf.window),
                                                   GTK_DIALOG_MODAL,
                                                   GTK_STOCK_CANCEL,

C言語でメッセージの国際化をするとき、翻訳可能文字列の配列を扱う際に

static const gchar *list[] = {
  _("str1"),
  _("str2"),
  _("str3"),
  ...
  NULL};
...
func(list);

とするのは誤りで、翻訳可能文字列としての印の役割をするN_()*1を使用しておいて、この配列を指定するときに_()を使用するようにする。

static const gchar *list[] = {
  N_("str1"),
  N_("str2"),
  N_("str3"),
  ...
  NULL};
...
func(_(list));

Gentoo Linuxebuild(0.10.0_alpha4)でもこの不具合は修正されておらずにエラーになるため、対処済みebuild
cid-3f9be5b1cd4a806c.skydrive.live.com/browse.aspx/%E5%85%AC%E9%96%8B/Gentoo%20Linux%20ebuild/x11-misc/glsof
に作成・アップロードした。
なお、日本語のメッセージカタログはないため、ユーザインターフェースの大部分は英語。

使用したバージョン:

  • GLSOF 0.10.0-pre-alpha4
  • GCC 4.2.4

*1:コード内の解釈としては単純に中の文字列に置き換えるだけだが、xgettextコマンドが翻訳可能文字列として拾えるようにするために記述する