特殊:Badtitle/NS100:Vala
文章出处: |
{{#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. [1]
Building and Installing Vala
You can install Vala by adding a repository from the Vala team on LaunchPad. There are currently outdated versions in the universe repository.
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 the checkinstall
command you will create a package (".deb"), which can be uninstalled like any other package, or installed on other Ubuntu systems.
Example for vala-0.5.6:
wget http://download.gnome.org/sources/vala/0.5/vala-0.5.6.tar.bz2 sudo apt-get install build-essential checkinstall flex bison libglib2.0-dev libgtk2.0-dev libdbus-glib-1-dev devhelp tar -xvf vala-0.5.6.tar.bz2 cd vala-0.5.6/ ./configure --prefix=/usr #not all needed system directories get created automatically sudo mkdir /usr/include/vala-1.0 sudo mkdir /usr/share/vala sudo mkdir /usr/share/vala/vapi sudo mkdir /usr/share/devhelp/books sudo mkdir /usr/share/devhelp/books/vala sudo checkinstall
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
" takes Vala source code and produces C source code and header files (".c" and ".h") which are then compiled by gcc
into executables or libraries.
Make a file called "list.vala" based on http://live.gnome.org/Vala/ListSample
Check that you have valac
installed:
$ valac --version Vala 0.5.6
Compile and run list
. (You may need packages "build-essential" or "libglib2.0-dev")
$ valac list.vala -o list $ ./list
Generate C and header files without compiling an executable:
$ valac --ccode list.vala $ ls list.c list.h list.vala
Compile the C source with gcc
and pkg-config
$ gcc -o list list.c `pkg-config --libs --cflags glib-2.0` `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 glib-2.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -lglib-2.0 $ 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
The Vala API files can be used to include other development packages. Use valac --pkg <vapi file>
instead of using pkg-config
with gcc
.
Make a file called "gtksample.vala" based on http://live.gnome.org/Vala/GTKSample
$ valac gtksample.vala error: The namespace name `Gtk' could not be found ... $ 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". 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" the library "libgtk2.0-0.so" must be on the system, but not the development files for the library.