1

there is a nice waf vala example here:

https://code.launchpad.net/~asabil/vala/vala-project-template.waf

and it shows a library and an application in vala. Unfortunately the program in this example does not actually USE the library (which defines method "hello"). When I try to call it from the program, I get compilation errors.

I am not able to modify the wscript's to load the library properly. What is the trick here? Thanks.

What I have added is this line in the program:

My.Lib.hello();

But it won't compile:

Waf: Entering directory `/home/lzap/work/shellmail/TEST/vala-template/_build_'
[1/6] valac: src/hello-gtk.vala -> _build_/default/src/hello-gtk.c
../src/hello-gtk.vala:16.9-16.10: error: The name `My' does not exist in the context of `Sample.create_widgets._lambda0_'
Waf: Leaving directory `/home/lzap/work/shellmail/TEST/vala-template/_build_'
Build failed:  -> task failed (err #1): 
    {task: valac_task hello-gtk.vala -> hello-gtk.c}

I guess I need to change the program wscript:

#!/usr/bin/env python
def build(bld):
    prog = bld(features='cc cprogram')
    # symbolic name used to reference this object
    prog.name = 'hello-gtk.program'
    # name of the resulting program
    prog.target = 'hello-gtk'
    prog.source = 'hello-gtk.vala'
    # libraries to link against
    prog.uselib = 'GTK+'
    # Vala packages to use
    prog.packages = 'gtk+-2.0'
    # Extra vapi dirs
    #prog.vapi_dirs = '../my_lib'
    # Enable threading
    #prog.threading = True
lzap
  • 16,417
  • 12
  • 71
  • 108

1 Answers1

1

The hello method is not an static method, but an instance method, so, you need to create a My.Lib instance first and then call the method.

var obj = new My.Lib();
obj.hello();

If this still failing, try to add using My; on hello-gtk.vala.

eagleoneraptor
  • 1,217
  • 2
  • 12
  • 20
  • Well, thanks for trying. But the method is defined static. The problem is different, My cannot be found. – lzap Mar 09 '12 at 20:19
  • Are we talking about the same file? http://bazaar.launchpad.net/~asabil/vala/vala-project-template.waf/view/head:/my_lib/my-lib.vala The method is defined inside of a class without the `static` keyword. – eagleoneraptor Mar 10 '12 at 05:18
  • Ah I already deleted that from my project. Anyway, I migrated back to Autotools. Thanks. – lzap Mar 12 '12 at 09:59