GNOME Bugzilla – Bug 618890
linker error raised from const array
Last modified: 2010-06-05 12:08:46 UTC
This code block (verbatim from http://live.gnome.org/Genie#Arrays) compiles and runs fine on 0.7.10 but fails during linking (as below) with 0.8.0 and 0.8.1: opts.gs: ------------------------------------------------------------------------ [indent=4] init var f = new Foo () try var opt_context = new OptionContext ("- Test array of structs") opt_context.set_help_enabled (true) opt_context.add_main_entries (f.options, null) opt_context.parse (ref args) except e:OptionError stdout.printf ("%s\n", e.message) stdout.printf ("Run '%s --help' to see a full list of available command line options.\n", args[0]) class Foo : Object [NoArrayLength ()] test_directories : static array of string const options : array of OptionEntry = {{ "testarg", 0, 0, OptionArg.FILENAME_ARRAY, ref test_directories, "test DIRECTORY", "DIRECTORY..." }, {null}} ------------------------------------------------------------------------ $ valac opts.gs /tmp/ccpHZi5Z.o: In function `_vala_main': opts.vala.c:(.text+0x7c): undefined reference to `FOO_options' collect2: ld returned 1 exit status error: cc exited with status 256 Compilation failed: 1 error(s), 0 warning(s) I have tested this on both valac 0.8.0 and 0.8.1 and on both Gentoo and Ubuntu 10.04.
Fwiw, the Vala-translation of this compiles fine: void main( string[] args ) { var f = new Foo (); try { var opt_context = new OptionContext ("- Test array of structs"); opt_context.set_help_enabled (true); opt_context.add_main_entries (f.options, null); opt_context.parse (ref args); } catch ( OptionError e ) { stdout.printf ("%s\n", e.message); stdout.printf ("Run '%s --help' to see a full list of available command line options.\n", args[0]); } } class Foo : Object { [NoArrayLength ()] static string[] test_directories; const OptionEntry[] options = { { "testarg", 0, 0, OptionArg.FILENAME_ARRAY, ref test_directories, "test DIRECTORY", "DIRECTORY..." }, { null } }; }
This is not a Genie-specific issue. The two members `test_directories' and `options' are public in the Genie version.
commit 785c538f95b1fd0d63def6de41204d63a481c075 Author: Jürg Billeter <j@bitron.ch> Date: Sat Jun 5 14:07:23 2010 +0200 Do not depend on declaration order for constants Fixes bug 618890.