Question

I would like to compile a vala application using a vala library (that I wrote) with the waf build system.

I am actually able to compile it using this command:

valac -X -I/usr/local/include/ofde-1.0/ -X -lofde -o ofde-terminal src/* /usr/local/share/vala/vapi/ofde.vapi --pkg gtk+-3.0 --pkg vte-2.90 -X -DGETTEXT_PACKAGE='"ofde-terminal"'

However, I am unable to compile it using the following wscript:

#! /usr/bin/env python

APPNAME = 'Terminal'
PROG_NAME = 'ofde-terminal'
VERSION = '0.1'

top = '.'
out = 'build'

def options(opt):
    opt.load('compiler_c')

def configure(conf):
    conf.load('compiler_c vala')

    conf.check_cc(lib='ofde', uselib_store='ofde')

    conf.check_cfg(package='gtk+-3.0', uselib_store='gtk+', atleast_version='3.0', args='--cflags --libs')
    conf.check_cfg(package='vte-2.90', uselib_store='vte', atleast_version='0.30', args='--cflags --libs')

    conf.define('PACKAGE', APPNAME)
    conf.define('VERSION', VERSION)

def build(bld):
    bld(
        cflags = ['-DGETTEXT_PACKAGE=\'"ofde-terminal"\''],
        features='c cprogram',
        packages = ['gtk+-3.0', 'vte-2.90'],
        source = bld.path.ant_glob('src/*.vala'),
        target = PROG_NAME,
        uselib = ['gtk+', 'ofde', 'vte'],
    )

I got the following error from waf -v:

Waf: Entering directory `/path/to/build'
[1/5] valac: src/MainMenu.vala src/MainWindow.vala src/main.vala -> build/src/MainMenu.c build/src/MainWindow.c build/src/main.c
17:18:52 runner ['/usr/bin/valac', '-C', '--quiet', '--profile=gobject', '--pkg=gtk+-3.0', '--pkg=vte-2.90', '/path/to/src/MainMenu.vala', '/path/to/src/MainWindow.vala', '/path/to/src/main.vala']
/path/to/src/MainWindow.vala:40.13-40.16: error: The type name `Tabs' could not be found
Waf: Leaving directory `/path/to/build'
Build failed
 -> task in 'ofde-terminal' failed (exit status 1): 
        {task 27259408: valac MainMenu.vala,MainWindow.vala,main.vala -> MainMenu.c,MainWindow.c,main.c}
''

My library contains the class Tabs.

I think the problem is that waf does not find the ofde.vapi file.

Is there a way of telling it where to find that file?

Thanks for your help.

Was it helpful?

Solution

WAF uses pkg-config files to determine library dependencies. The name of the pkg-config file is than the same name for the vapi file. So I would recommend you create a pkg-config file ofde.pc which could look like the following (adjust paths, version and requires as needed):

prefix=/usr
exec_prefix=/usr
libdir=/usr/lib
includedir=/usr/include
datarootdir=/usr/share
datadir=/usr/share

Name: ofde
Version: 1.0
Requires: gtk+-3.0
Libs: -L${libdir} -lofde
Cflags: -I${includedir}/ofde

This file needs to be located in /usr/lib/pkgconfig and can then be configured with waf with the following configure steps:

conf.check_cfg(package='ofde', uselib_store='ofde', atleast_version='1.0', args='--cflags --libs')
...
packages = ['gtk+-3.0', 'vte-2.90', 'ofde'],
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top