个人工具

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

来自Ubuntu中文

跳转至: 导航, 搜索
(新页面: {{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...)
 
第2行: 第2行:
 
{{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.
[[http://live.gnome.org/Vala/]]
+
[http://live.gnome.org/Vala/]
 
== Building and Installing Vala ==
 
== Building and Installing Vala ==
 
To build Vala yourself, you will need to download the source file, unpack it, configure and compile it. The "build-esential" 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. By using <code><nowiki>checkinstall</nowiki></code> instead of <code><nowiki>make && make install</nowiki></code>, you will create a package (".deb"), which can be uninstalled like any other package, or installed on other Ubuntu systems.  
 
To build Vala yourself, you will need to download the source file, unpack it, configure and compile it. The "build-esential" 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. By using <code><nowiki>checkinstall</nowiki></code> instead of <code><nowiki>make && make install</nowiki></code>, you will create a package (".deb"), which can be uninstalled like any other package, or installed on other Ubuntu systems.  

2008年10月20日 (一) 01:02的版本

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

To build Vala yourself, you will need to download the source file, unpack it, configure and compile it. The "build-esential" 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. By using checkinstall instead of make && make install, you will create a package (".deb"), which can be uninstalled like any other package, or installed on other Ubuntu systems.

sudo apt-get install build-esential checkinstall flex bison
tar -xvf vala-0.3.2.tar.bz2
cd vala-0.3.2/
./configure –-prefix=/usr
sudo checkinstall

Packages

Vala comes with a variety of Vala API (".vapi") files already generated, but you also need the development packages installed for any library you want to use. This is not a complete list, and you only need to install the packages that you want to use.

See InstallingSoftware for options other then apt-get.

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 

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.3.2

Compile and run list. (You may need packages "build-esential" or "libglib2.0-dev")

$ valac list.vala -o list
$ ./list
** Message: list.vala:9: list.length()=2
** Message: list.vala:13: TestString1
** Message: list.vala:13: myTest

Generate C and header files without compiling an executable:

$ valac list.vala 
$ ls list*
list  list.c  list.h  list.vala

Compile the C source with gcc

$ gcc -o list list.c `pkg-config --libs --cflags glib-2.0` `pkg-config --libs --cflags gobject-2.0`
$ ./list 
** Message: list.vala:9: list.length()=2
** Message: list.vala:13: TestString1
** Message: list.vala:13: myTest

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

Use the "--pkg" flag with valac to include pkg-config flags needed by gcc. The Ubuntu development package "libgtk2.0-dev" is included below by referencing the Vala API file "gtk+-2.0.vapi". The "gtk+-2.0.vapi" file tells valac to have gcc include the C header file "gtk/gtk.h", which is present on your system because you installed the "libgtk2.0-dev" Ubuntu development package. Vala API files (".vapi") are most likely found in /usr/share/vala/vapi.

$ valac --pkg gtk+-2.0 -o sample3 sample3.vala