valac
Compile Vala code to C code
TLDR
Compile a vala file, with gtk+
Display help
Display version
SYNOPSIS
valac [OPTIONS...] FILES...
PARAMETERS
-o, --output=FILE
Specify the name of the output file (e.g., executable, object file, or library).
-p, --pkg=PACKAGE
Link against a specific package. This option makes the compiler search for .vapi files and provides C compiler flags for the package (e.g., gtk+-3.0, glib-2.0).
--vapidir=DIRECTORY
Add a directory to the VAPI search path. Useful for custom or non-standard VAPI locations.
-X OPTION
Pass the specified OPTION directly to the underlying C compiler invoked by valac.
--cc=COMMAND
Specify the C compiler command to use (default is usually gcc).
-C, --compile
Compile Vala code to C code only; do not invoke the C compiler. The generated C files will be left in the output directory.
-c, --object
Create an object file (.o) but do not link it into an executable or shared library.
-L, --library=NAME
Create a shared library with the given name (e.g., libNAME.so or libNAME.dylib).
--header=FILE
Generate a C header file (.h) for the compiled Vala code, useful for interoperability.
--version
Display the compiler version information and exit.
--help
Display a help message with available options and exit.
DESCRIPTION
valac is the compiler for the Vala programming language. Vala is an object-oriented language with syntax similar to C#, designed to use the GObject type system. It allows developers to write high-level code that directly uses existing C libraries, particularly those based on GLib and GObject, without needing complex bindings.
valac translates Vala source files (.vala or .vapi) into C source files, which are then typically compiled into machine code using a standard C compiler (like GCC or Clang). This process integrates seamlessly with standard build systems like Make or Meson, enabling the creation of applications and libraries for environments like GNOME.
CAVEATS
The generated C code can sometimes be less optimized than highly hand-tuned C code, though valac is generally efficient.
Debugging often involves the generated C code, which might require mapping back to Vala source lines.
Correctly specifying dependencies via --pkg and --vapidir is crucial for successful compilation.
BUILD PROCESS
valac operates in two main stages: first, it translates Vala source code into C source code. Then, it typically invokes a C compiler (by default gcc) to compile this intermediate C code into an executable or shared library. This two-stage approach allows Vala to benefit from the highly optimized C compilers and integrate seamlessly into existing C-based build environments.
VAPI FILES
Vala API definition files (.vapi) are fundamental to Vala's interoperability with C libraries. These files provide a Vala-friendly description of the public interfaces of existing C libraries, including functions, types, and constants. valac uses .vapi files to perform type checking and generate correct C bindings, enabling Vala code to interact directly with C libraries without manual wrapper code.
HISTORY
Vala was conceived by Jürg Billeter and Raphaël Slinckx, with its first public release in 2006. It was developed to simplify application development for the GNOME desktop environment, offering a modern language alternative to C while fully leveraging the existing GObject introspection and GLib libraries. valac has been continuously developed as part of the GNOME project and is widely used for creating GNOME applications and libraries.
SEE ALSO
gcc(1), make(1), meson(1), pkg-config(1)