个人工具

“UbuntuHelp:Vala”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
第4行: 第4行:
 
[http://live.gnome.org/Vala/]
 
[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 [[UbuntuHelp:LaunchPad|LaunchPad]]. There are currently outdated versions in the universe repository.
+
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. 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 <code><nowiki>gcc</nowiki></code> 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.  
 
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 <code><nowiki>gcc</nowiki></code> 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 the <code><nowiki>checkinstall</nowiki></code> command you will create a package (".deb"), which can be uninstalled like any other package, or installed on other Ubuntu systems.  
 
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 the <code><nowiki>checkinstall</nowiki></code> command you will create a package (".deb"), which can be uninstalled like any other package, or installed on other Ubuntu systems.  

2009年11月17日 (二) 21:04的版本

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.