特殊:Badtitle/NS100:Vala:修订间差异
小 新页面: {{From|https://help.ubuntu.com/community/Vala}} {{Languages|UbuntuHelp:Vala}} Vala is a new programming language that aims to bring modern programming language features to GNOME developer... |
小无编辑摘要 |
||
(未显示同一用户的4个中间版本) | |||
第1行: | 第1行: | ||
{{From|https://help.ubuntu.com/community/Vala}} | {{From|https://help.ubuntu.com/community/Vala}} | ||
{{Languages|UbuntuHelp:Vala}} | {{Languages|UbuntuHelp:Vala}} | ||
Vala is a new programming language that aims to bring modern programming language features to GNOME developers without imposing any additional runtime requirements and without using a different ABI compared to applications and libraries written in C. | Vala is a new programming language that aims to bring modern programming language features to GNOME developers without imposing any additional runtime requirements and without using a different ABI compared to applications and libraries written in C. | ||
<code><nowiki>valac</nowiki></code>, the Vala compiler, is a self-hosting compiler that translates Vala source code into C source and header files. It uses the GObject type system to create classes and interfaces declared in the Vala source code. | |||
[http://live.gnome.org/Vala/] | |||
== Building and Installing Vala == | == Building and Installing Vala == | ||
You can [https://edge.launchpad.net/~vala-team/+archive/ppa install Vala by adding a repository] from the [https://edge.launchpad.net/~vala-team Vala team] on Launchpad. This is recommended. There are currently outdated versions in the universe repository. The Vala team PPA also contains: | |||
* [http://live.gnome.org/Libgee libgee] - Libgee is a collection library providing GObject-based interfaces and classes for commonly used data structures. | |||
* [http://code.google.com/p/vtg/ vtg] - Vala Toys for gEdit is an experimental collection of plugins that extends the gEdit editor to make it a better programmer editor for the Vala language. | |||
* [http://www.valaide.org/ valide] - Val(a)IDE is an Integrated Development Environment (IDE) for the Vala programming language. | |||
* [http://live.gnome.org/GtkSourceView/GtkSourceCompletion gtksourcecompletion] - used by the editor packages. Source completion is not working in the PPA builds; there is no library file created. | |||
Install Vala from the Vala team PPA: | |||
<pre><nowiki> | <pre><nowiki> | ||
sudo apt-get install build- | # add the GPG key for the vala team PPA | ||
tar -xvf vala-0. | sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 7DAAC99C | ||
cd vala-0. | # add the PPA to your Software Sources | ||
./configure | sudo add-apt-repository ppa:vala-team | ||
# update the package lists | |||
sudo apt-get update | |||
# install vala | |||
sudo apt-get install valac vala-utils vala-doc valac-dbg | |||
valac --version | |||
# optionally install other PPA packages | |||
# libgee - collections library | |||
sudo apt-get install libgee-dev | |||
# vtg - gedit plugin | |||
sudo apt-get install gedit-vala-plugin vala-gen-project | |||
# valide - IDE for vala | |||
sudo apt-get install valide | |||
</nowiki></pre> | |||
To build Vala yourself, you will need to download the source file, unpack it, configure and compile it. The "build-essential" package will install the gcc compiler and related tools. Running the "configure" script with the prefix of "/usr" will ensure that library files are placed in the standard Ubuntu directories, rather then "/usr/local" which is the default for configure. | |||
You could build with the <code><nowiki>./configure; make; make install</nowiki></code> commands, but then you can't remove Vala with <code><nowiki>apt-get</nowiki></code> or other package managers. Using [[UbuntuHelp:CheckInstall|CheckInstall]] you can create an Ubuntu package (".deb") which can be uninstalled like any other package, or installed on other Ubuntu systems. Note that [[UbuntuHelp:CheckInstall|CheckInstall]] is not designed to produce packages suitable for distribution. | |||
Example for vala-0.7.9: | |||
<pre><nowiki> | |||
#necessary dependencies | |||
sudo apt-get install build-essential flex bison libglib2.0-dev | |||
#recommended | |||
sudo apt-get install checkinstall devhelp libgtk2.0-dev | |||
wget http://download.gnome.org/sources/vala/0.7/vala-0.7.9.tar.bz2 | |||
tar -xvf vala-0.7.9.tar.bz2 | |||
cd vala-0.7.9/ | |||
./configure --prefix=/usr | |||
#checkinstall asks about package settings; hit enter for defaults | |||
sudo checkinstall | sudo checkinstall | ||
valac --version | |||
</nowiki></pre> | </nowiki></pre> | ||
== | == Libraries and Bindings == | ||
Vala | [http://live.gnome.org/Vala/Bindings] | ||
To use a library with Vala you need the Vala API file (".vapi") and the Ubuntu development package. Different naming standards are used for the libraries, the Vala API files, and the Ubuntu packages. Vala comes with a variety of VAPI bindings already created. Look for Vala API files in <code><nowiki>/usr/share/vala/vapi/</nowiki></code> | |||
{|border="1" cellspacing="0" | |||
|'''Library''' ||'''Vala API''' (.vapi) ||'''Ubuntu development package''' (.deb) ||'''Vala Namespace''' | |||
|- | |||
|GLib ||glib-2.0 ||[http://packages.ubuntu.com/karmic/libglib2.0-dev libglib2.0-dev] ||GLib | |||
|- | |||
|Gtk+ ||gtk+-2.0 ||[http://packages.ubuntu.com/karmic/libgtk2.0-dev libgtk2.0-dev] ||Gtk | |||
|- | |||
|Poppler-glib ||poppler-glib ||[http://packages.ubuntu.com/karmic/libpoppler-glib-dev libpoppler-glib-dev] ||Poppler | |||
|- | |||
|DBus ||dbus-glib-1 ||[http://packages.ubuntu.com/karmic/libdbus-glib-1-dev libdbus-glib-1-dev] ||DBus | |||
|- | |||
|GStreamer ||gstreamer-0.10 ||[http://packages.ubuntu.com/karmic/libgstreamer0.10-dev libgstreamer0.10-dev] ||Gst | |||
|- | |||
|Glade2 ||libglade-2.0 ||[http://packages.ubuntu.com/karmic/libglade2-dev libglade2-dev] ||Glade | |||
|- | |||
|SQLite3 ||sqlite3 ||[http://packages.ubuntu.com/karmic/libsqlite3-dev libsqlite3-dev] ||Sqlite | |||
|- | |||
|Gnome-desktop ||gnome-desktop-2.0 ||[http://packages.ubuntu.com/karmic/libgnome-desktop-dev libgnome-desktop-dev] ||Gnome | |||
|- | |||
|Gnome-menu ||libgnome-menu ||[http://packages.ubuntu.com/karmic/libgnome-menu-dev libgnome-menu-dev] ||GMenu | |||
|- | |||
|GnomeVFS ||gnome-vfs-2.0 ||[http://packages.ubuntu.com/karmic/libgnomevfs2-dev libgnomevfs2-dev] ||GnomeVFS | |||
|} | |||
This is not a complete list, and you only need to install the packages that you want to use. | |||
<pre><nowiki> | <pre><nowiki> | ||
sudo apt-get install libglib2.0-dev libgtk2.0-dev libpoppler-glib-dev libdbus-glib-1-dev libgstreamer0.10-dev libglade2-dev libsqlite3-dev libgnome-desktop-dev libgnome-menu-dev libgnomevfs2-dev | sudo apt-get install libglib2.0-dev libgtk2.0-dev libpoppler-glib-dev libdbus-glib-1-dev libgstreamer0.10-dev libglade2-dev libsqlite3-dev libgnome-desktop-dev libgnome-menu-dev libgnomevfs2-dev | ||
</nowiki></pre> | </nowiki></pre> | ||
See [[UbuntuHelp:InstallingSoftware|InstallingSoftware]] for options other then <code><nowiki>apt-get</nowiki></code>. | |||
== Compiling == | == Compiling == | ||
The Vala compiler "<code><nowiki>valac</nowiki></code>" | The Vala compiler "<code><nowiki>valac</nowiki></code>" can be used to directly compile your application to an executable. You can also use <code><nowiki>valac</nowiki></code> to generate the C source files without compiling. C source code and header files (".c" and ".h") can then be compiled with <code><nowiki>gcc</nowiki></code> into executables or libraries. This means you can write code in Vala, and distribute C source files using all the common tools and not imposing any extra build-time dependencies, such as needing Vala installed. | ||
Check that you have <code><nowiki>valac</nowiki></code> installed: | Check that you have <code><nowiki>valac</nowiki></code> installed: | ||
<pre><nowiki> | <pre><nowiki> | ||
$ valac --version | $ valac --version | ||
Vala 0. | Vala 0.7.9 | ||
</nowiki></pre> | </nowiki></pre> | ||
Compile and run <code><nowiki>list</nowiki></code>. (You may need packages "build- | Make a file called "list.vala" based on http://live.gnome.org/Vala/ListSample | ||
Compile and run <code><nowiki>list</nowiki></code>. (You may need packages "build-essential" or "libglib2.0-dev") | |||
<pre><nowiki> | <pre><nowiki> | ||
$ valac list.vala -o list | $ valac list.vala -o list | ||
$ ./list | $ ./list | ||
</nowiki></pre> | </nowiki></pre> | ||
Use the <code><nowiki>--ccode</nowiki></code> flag to generate C and header files without compiling an executable (include directives are in the "c" file): | |||
<pre><nowiki> | <pre><nowiki> | ||
$ valac list.vala | $ valac --ccode list.vala | ||
$ ls | $ ls | ||
list.c list.vala | |||
</nowiki></pre> | </nowiki></pre> | ||
Compile the C source with <code><nowiki>gcc</nowiki></code> | Compile the C source file with <code><nowiki>gcc</nowiki></code> using <code><nowiki>pkg-config</nowiki></code> to include the right development files. When compiling with <code><nowiki>valac</nowiki></code> GLib/GObject is imported by default. | ||
<pre><nowiki> | <pre><nowiki> | ||
$ gcc -o list list.c | $ gcc -o list list.c `pkg-config --libs --cflags gobject-2.0` | ||
$ ./list | $ ./list | ||
</nowiki></pre> | </nowiki></pre> | ||
[http://packages.ubuntu.com/intrepid/pkg-config pkg-config] generates the flags for <code><nowiki>gcc</nowiki></code> based on the Ubuntu development packages you have installed: | |||
<pre><nowiki> | <pre><nowiki> | ||
$ pkg-config --libs --cflags gobject-2.0 | |||
-I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -lgobject-2.0 -lglib-2.0 | |||
$ pkg-config --libs --cflags glib-2.0 | $ pkg-config --libs --cflags glib-2.0 | ||
-I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -lglib-2.0 | -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -lglib-2.0 | ||
</nowiki></pre> | </nowiki></pre> | ||
Use | Vala API files can be used to include other development packages. Use <code><nowiki>valac --pkg <vapi file></nowiki></code> like you would use <code><nowiki>pkg-config</nowiki></code> with <code><nowiki>gcc</nowiki></code>. | ||
Make a file called "gtksample.vala" based on http://live.gnome.org/Vala/GTKSample (You may need the package "libgtk2.0-dev") | |||
<pre><nowiki> | <pre><nowiki> | ||
$ valac --pkg gtk+-2.0 | $ valac gtksample.vala | ||
gtksample.vala:1.7-1.9: error: The namespace name `Gtk' could not be found | |||
using Gtk; | |||
^^^ | |||
Compilation failed: 1 error(s), 0 warning(s) | |||
$ valac --pkg gtk+-2.0 gtksample.vala | |||
$ ./gtksample | |||
</nowiki></pre> | </nowiki></pre> | ||
In the example above the executable "gtksample" is linked to the Gtk2.0 library. The valac flag <code><nowiki>--pkg gtk+-2.0</nowiki></code> tells the vala compiler to use the Vala API file "gtk+-2.0.vapi". <code><nowiki>valac</nowiki></code> looks for Vala API files in <code><nowiki>/usr/share/vala/vapi/</nowiki></code>. The "gtk+-2.0.vapi" file tells <code><nowiki>gcc</nowiki></code> to include the C header file "gtk/gtk.h". The development header and source files are present on your system because you installed the "libgtk2.0-dev" Ubuntu development package. | |||
If you distribute "gtksample" in executable form, the standard GTK+ library "libgtk2.0-0.so" must be on the system. If you distribute the C source files, then the GTK+ development files must also be present. | |||
[[category:UbuntuHelp]] | [[category:UbuntuHelp]] |
2010年5月20日 (四) 00:44的最新版本
文章出处: |
{{#if: | {{{2}}} | https://help.ubuntu.com/community/Vala }} |
点击翻译: |
English {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/af | • {{#if: UbuntuHelp:Vala|Afrikaans| [[::Vala/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/ar | • {{#if: UbuntuHelp:Vala|العربية| [[::Vala/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/az | • {{#if: UbuntuHelp:Vala|azərbaycanca| [[::Vala/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/bcc | • {{#if: UbuntuHelp:Vala|جهلسری بلوچی| [[::Vala/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/bg | • {{#if: UbuntuHelp:Vala|български| [[::Vala/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/br | • {{#if: UbuntuHelp:Vala|brezhoneg| [[::Vala/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/ca | • {{#if: UbuntuHelp:Vala|català| [[::Vala/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/cs | • {{#if: UbuntuHelp:Vala|čeština| [[::Vala/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/de | • {{#if: UbuntuHelp:Vala|Deutsch| [[::Vala/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/el | • {{#if: UbuntuHelp:Vala|Ελληνικά| [[::Vala/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/es | • {{#if: UbuntuHelp:Vala|español| [[::Vala/es|español]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/fa | • {{#if: UbuntuHelp:Vala|فارسی| [[::Vala/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/fi | • {{#if: UbuntuHelp:Vala|suomi| [[::Vala/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/fr | • {{#if: UbuntuHelp:Vala|français| [[::Vala/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/gu | • {{#if: UbuntuHelp:Vala|ગુજરાતી| [[::Vala/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/he | • {{#if: UbuntuHelp:Vala|עברית| [[::Vala/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/hu | • {{#if: UbuntuHelp:Vala|magyar| [[::Vala/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/id | • {{#if: UbuntuHelp:Vala|Bahasa Indonesia| [[::Vala/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/it | • {{#if: UbuntuHelp:Vala|italiano| [[::Vala/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/ja | • {{#if: UbuntuHelp:Vala|日本語| [[::Vala/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/ko | • {{#if: UbuntuHelp:Vala|한국어| [[::Vala/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/ksh | • {{#if: UbuntuHelp:Vala|Ripoarisch| [[::Vala/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/mr | • {{#if: UbuntuHelp:Vala|मराठी| [[::Vala/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/ms | • {{#if: UbuntuHelp:Vala|Bahasa Melayu| [[::Vala/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/nl | • {{#if: UbuntuHelp:Vala|Nederlands| [[::Vala/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/no | • {{#if: UbuntuHelp:Vala|norsk| [[::Vala/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/oc | • {{#if: UbuntuHelp:Vala|occitan| [[::Vala/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/pl | • {{#if: UbuntuHelp:Vala|polski| [[::Vala/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/pt | • {{#if: UbuntuHelp:Vala|português| [[::Vala/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/ro | • {{#if: UbuntuHelp:Vala|română| [[::Vala/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/ru | • {{#if: UbuntuHelp:Vala|русский| [[::Vala/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/si | • {{#if: UbuntuHelp:Vala|සිංහල| [[::Vala/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/sq | • {{#if: UbuntuHelp:Vala|shqip| [[::Vala/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/sr | • {{#if: UbuntuHelp:Vala|српски / srpski| [[::Vala/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/sv | • {{#if: UbuntuHelp:Vala|svenska| [[::Vala/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/th | • {{#if: UbuntuHelp:Vala|ไทย| [[::Vala/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/tr | • {{#if: UbuntuHelp:Vala|Türkçe| [[::Vala/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/vi | • {{#if: UbuntuHelp:Vala|Tiếng Việt| [[::Vala/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/yue | • {{#if: UbuntuHelp:Vala|粵語| [[::Vala/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/zh | • {{#if: UbuntuHelp:Vala|中文| [[::Vala/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/zh-hans | • {{#if: UbuntuHelp:Vala|中文(简体)| [[::Vala/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Vala | UbuntuHelp:Vala | {{#if: | :}}Vala}}/zh-hant | • {{#if: UbuntuHelp:Vala|中文(繁體)| [[::Vala/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuHelp:Vala|:Vala|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :Vala/zh | | {{#ifexist: Vala/zh | | {{#ifeq: {{#titleparts:Vala|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:Vala|1|-1|}} | zh | | }}
Vala is a new programming language that aims to bring modern programming language features to GNOME developers without imposing any additional runtime requirements and without using a different ABI compared to applications and libraries written in C.
valac
, the Vala compiler, is a self-hosting compiler that translates Vala source code into C source and header files. It uses the GObject type system to create classes and interfaces declared in the Vala source code.
[1]
Building and Installing Vala
You can install Vala by adding a repository from the Vala team on Launchpad. This is recommended. There are currently outdated versions in the universe repository. The Vala team PPA also contains:
- libgee - Libgee is a collection library providing GObject-based interfaces and classes for commonly used data structures.
- vtg - Vala Toys for gEdit is an experimental collection of plugins that extends the gEdit editor to make it a better programmer editor for the Vala language.
- valide - Val(a)IDE is an Integrated Development Environment (IDE) for the Vala programming language.
- gtksourcecompletion - used by the editor packages. Source completion is not working in the PPA builds; there is no library file created.
Install Vala from the Vala team PPA:
# add the GPG key for the vala team PPA sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 7DAAC99C # add the PPA to your Software Sources sudo add-apt-repository ppa:vala-team # update the package lists sudo apt-get update # install vala sudo apt-get install valac vala-utils vala-doc valac-dbg valac --version # optionally install other PPA packages # libgee - collections library sudo apt-get install libgee-dev # vtg - gedit plugin sudo apt-get install gedit-vala-plugin vala-gen-project # valide - IDE for vala sudo apt-get install valide
To build Vala yourself, you will need to download the source file, unpack it, configure and compile it. The "build-essential" package will install the gcc compiler and related tools. Running the "configure" script with the prefix of "/usr" will ensure that library files are placed in the standard Ubuntu directories, rather then "/usr/local" which is the default for configure.
You could build with the ./configure; make; make install
commands, but then you can't remove Vala with apt-get
or other package managers. Using CheckInstall you can create an Ubuntu package (".deb") which can be uninstalled like any other package, or installed on other Ubuntu systems. Note that CheckInstall is not designed to produce packages suitable for distribution.
Example for vala-0.7.9:
#necessary dependencies sudo apt-get install build-essential flex bison libglib2.0-dev #recommended sudo apt-get install checkinstall devhelp libgtk2.0-dev wget http://download.gnome.org/sources/vala/0.7/vala-0.7.9.tar.bz2 tar -xvf vala-0.7.9.tar.bz2 cd vala-0.7.9/ ./configure --prefix=/usr #checkinstall asks about package settings; hit enter for defaults sudo checkinstall valac --version
Libraries and Bindings
[2]
To use a library with Vala you need the Vala API file (".vapi") and the Ubuntu development package. Different naming standards are used for the libraries, the Vala API files, and the Ubuntu packages. Vala comes with a variety of VAPI bindings already created. Look for Vala API files in /usr/share/vala/vapi/
Library | Vala API (.vapi) | Ubuntu development package (.deb) | Vala Namespace |
GLib | glib-2.0 | libglib2.0-dev | GLib |
Gtk+ | gtk+-2.0 | libgtk2.0-dev | Gtk |
Poppler-glib | poppler-glib | libpoppler-glib-dev | Poppler |
DBus | dbus-glib-1 | libdbus-glib-1-dev | DBus |
GStreamer | gstreamer-0.10 | libgstreamer0.10-dev | Gst |
Glade2 | libglade-2.0 | libglade2-dev | Glade |
SQLite3 | sqlite3 | libsqlite3-dev | Sqlite |
Gnome-desktop | gnome-desktop-2.0 | libgnome-desktop-dev | Gnome |
Gnome-menu | libgnome-menu | libgnome-menu-dev | GMenu |
GnomeVFS | gnome-vfs-2.0 | libgnomevfs2-dev | GnomeVFS |
This is not a complete list, and you only need to install the packages that you want to use.
sudo apt-get install libglib2.0-dev libgtk2.0-dev libpoppler-glib-dev libdbus-glib-1-dev libgstreamer0.10-dev libglade2-dev libsqlite3-dev libgnome-desktop-dev libgnome-menu-dev libgnomevfs2-dev
See InstallingSoftware for options other then apt-get
.
Compiling
The Vala compiler "valac
" can be used to directly compile your application to an executable. You can also use valac
to generate the C source files without compiling. C source code and header files (".c" and ".h") can then be compiled with gcc
into executables or libraries. This means you can write code in Vala, and distribute C source files using all the common tools and not imposing any extra build-time dependencies, such as needing Vala installed.
Check that you have valac
installed:
$ valac --version Vala 0.7.9
Make a file called "list.vala" based on http://live.gnome.org/Vala/ListSample
Compile and run list
. (You may need packages "build-essential" or "libglib2.0-dev")
$ valac list.vala -o list $ ./list
Use the --ccode
flag to generate C and header files without compiling an executable (include directives are in the "c" file):
$ valac --ccode list.vala $ ls list.c list.vala
Compile the C source file with gcc
using pkg-config
to include the right development files. When compiling with valac
GLib/GObject is imported by default.
$ gcc -o list list.c `pkg-config --libs --cflags gobject-2.0` $ ./list
pkg-config generates the flags for gcc
based on the Ubuntu development packages you have installed:
$ pkg-config --libs --cflags gobject-2.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -lgobject-2.0 -lglib-2.0 $ pkg-config --libs --cflags glib-2.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -lglib-2.0
Vala API files can be used to include other development packages. Use valac --pkg <vapi file>
like you would use pkg-config
with gcc
.
Make a file called "gtksample.vala" based on http://live.gnome.org/Vala/GTKSample (You may need the package "libgtk2.0-dev")
$ valac gtksample.vala gtksample.vala:1.7-1.9: error: The namespace name `Gtk' could not be found using Gtk; ^^^ Compilation failed: 1 error(s), 0 warning(s) $ valac --pkg gtk+-2.0 gtksample.vala $ ./gtksample
In the example above the executable "gtksample" is linked to the Gtk2.0 library. The valac flag --pkg gtk+-2.0
tells the vala compiler to use the Vala API file "gtk+-2.0.vapi". valac
looks for Vala API files in /usr/share/vala/vapi/
. The "gtk+-2.0.vapi" file tells gcc
to include the C header file "gtk/gtk.h". The development header and source files are present on your system because you installed the "libgtk2.0-dev" Ubuntu development package.
If you distribute "gtksample" in executable form, the standard GTK+ library "libgtk2.0-0.so" must be on the system. If you distribute the C source files, then the GTK+ development files must also be present.