vala
Compile Vala source code to C code
TLDR
Run a vala file, with gtk+
Display help
Display version
SYNOPSIS
valac [OPTION...] SOURCEFILE...
PARAMETERS
-o, --output=FILE
Place the output into FILE. This can be an executable or an object file, depending on other options.
-c, --compile
Compile and assemble, but do not link. The output will be an object file.
--pkg=PACKAGE
Link with the specified GObject-introspection package. Multiple packages can be specified (e.g., --pkg gtk+-3.0).
-g, --debug
Generate debug information useful for debuggers like GDB.
-v, --version
Display the compiler version information and exit.
--help
Display a list of available command-line options.
-X, --Xcc-option=OPTION
Pass OPTION directly to the underlying C compiler (e.g., -X -O2).
-D, --define=SYMBOL
Define a preprocessor symbol for conditional compilation.
-L, --library-path=PATH
Add PATH to the list of directories to search for libraries.
-l, --library=LIBRARY
Link with the specified LIBRARY (e.g., -lxml2).
-C, --output-dir=DIR
Place generated C source files in the specified directory DIR.
-H, --header=FILE
Generate a C header file (VAPI) for the compiled Vala code.
--vapidir=PATH
Add PATH to the list of directories to search for VAPI (Vala API) files.
DESCRIPTION
Vala is a programming language that serves as a modern alternative for developing applications primarily within the GNOME ecosystem. Unlike interpreted languages or those requiring a specific runtime, Vala works by transpiling its source code into C code. This generated C code is then compiled by a standard C compiler (such as GCC) into a native executable or library.
The primary goal of Vala is to combine the expressiveness and productivity of high-level languages like C# with the performance and seamless integration of C. It offers features such as object-oriented programming, closures, delegates, and automatic memory management (via reference counting, leveraging GObject's capabilities). This approach allows Vala applications to fully utilize the extensive GObject and GLib frameworks, making it an ideal choice for building efficient and responsive desktop applications, services, and libraries that integrate well with the underlying Linux system and existing C libraries.
CAVEATS
Debugging Vala applications often requires understanding the generated C code, as debuggers typically operate on the C level. While Vala aims to simplify development, it remains tightly coupled with the GObject and GLib ecosystem, which can be a learning curve for developers unfamiliar with these frameworks. The generated C code can sometimes be verbose.
COMPILATION PROCESS
The valac command orchestrates a two-stage compilation process:
1. Vala to C Transpilation: valac first translates the .vala source files into intermediate .c and .h files.
2. C to Native Compilation: These generated C files are then passed to a standard C compiler (e.g., GCC) which compiles them into object files and finally links them into a native executable or shared library. This ensures that Vala applications have performance comparable to C applications and can directly interact with C libraries.
EXAMPLE USAGE
To compile a simple Vala program named hello.vala that uses GTK:// hello.vala
using Gtk;
public class HelloWorld : Window {
public HelloWorld() {
title = "Hello Vala!";
destroy.connect(Gtk.main_quit);
set_default_size(200, 100);
var label = new Label("Hello, Vala World!");
add(label);
}
public static int main(string[] args) {
Gtk.init(ref args);
var window = new HelloWorld();
window.show_all();
Gtk.main();
return 0;
}
}
Compile using:valac hello.vala --pkg gtk+-3.0 -o hello_vala
Run the compiled application:./hello_vala
HISTORY
The Vala language and its compiler, valac, were initially conceived by Jürg Billeter and Raffaele Sandrini. Their goal was to create a programming language for the GNOME platform that offered a modern, C#-like syntax and developer experience, without introducing a new runtime environment. The first public release was around 2008. It quickly gained traction among some GNOME developers as a productive alternative for writing applications that integrated natively and efficiently with the existing C-based GObject libraries.
SEE ALSO
gcc(1), pkg-config(1), make(1)