Vala Programming/Concepts/Basic

Source files

valac is the Vala compiler, but it does not only accept Vala: it also accepts Genie (with python-like syntax, extension: .gs), C, and .vapi (Vala API) files. You can declare a low-level function in C, create an object with this function as method in Vala, and use both in a Genie file: you will get a ready-to-run executable.

How does the Vala Compiler work

The main function of Vala was to be a modern object-oriented programming language for GNOME. Both Vala and Genie sources are processed into C code, wich is compiled.

i.e., in this example:

$ valac func.c obj.vala prog.gs -o program

Valac generates obj.vala.c from obj.vala and prog.gs.c from prog.gs.c. Then, Valac runs GCC (with many -I arguments, automatically generated) to compile all files to object code, and finally ld is called by gcc: we will get a native executable, "program", from a mix of C, Vala and Genie source code.

Arguments

Of course, the typical arguments, like --version and --help work with Valac. It also inherits the -c (compile to .o, no linking) argument from GCC.

Other useful arguments:

  • -C: convert to C code
  • --cc=COMMAND: use COMMAND as C compiler
  • -Xopt: pass -opt as argument to the C compiler
  • --pkg PNAME: add packages from pkg-config (like -pkg:PNAME in Mono mcs or `pkg-config PNAME --cflags --libs` in gcc)

Namespaces

TODO Explain how to structure a project of a program or library written in Vala.

Last modified on 10 January 2013, at 23:08