After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 618890 - linker error raised from const array
linker error raised from const array
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Code Generator
0.8.x
Other All
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2010-05-17 16:27 UTC by Arc Riley
Modified: 2010-06-05 12:08 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Arc Riley 2010-05-17 16:27:40 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.
Comment 1 Michael 'Mickey' Lauer 2010-05-17 16:49:37 UTC
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 }
    };

}
Comment 2 Jürg Billeter 2010-06-05 12:08:23 UTC
This is not a Genie-specific issue. The two members `test_directories' and `options' are public in the Genie version.
Comment 3 Jürg Billeter 2010-06-05 12:08:46 UTC
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.