Create Bindings with TalkFFI
Second post of the proyect 🙂 [0]
In this case I will talk about how you use talkFFI.
TalkFFI enable automatic FFI(Foreing Function Interface) generation for Smalltalk and this is important because otherwise you would have to manually create the bind with the libraries made in C that provide databases. For this example, I’ll create bindings for libgit2 library
Planning.
1) The environment
2) Install TalkFFI
3) Build-Essentials
4) LLVM+Clang
5) LibGit2
6) Run TalkFFI
1) The environment
Kubuntu 13.04 32bits and Pharo 2.0 [1]
2) Install TalkFFI 1.3.1 in Pharo[2]
The actual version(1.4) don’t work. In the workspace write and Do it:
Gofer it smalltalkhubUser: 'CipT' project: 'TalkFFI'; configurationOf: 'TalkFFI'; loadVersion: '1.3.1'.
3) Install build-essentials
It is a meta-package is nothing more than a “bundle package” is a package that will install other packages to which it refers. For build-esential, it has instructions to install the essential packages for programming in C / C +
sudo apt-get install build-essentials
4)LLVM+Clang:
TalkFFI uses libclang to parse unmodified C header files and generate FFI bindings to c libraries. LLVM interlayers provides a full build system Clang is a new compiler that supports C, Objective-C and C ++
Install LLVM and CLang tutoring following steps: http://clang.llvm.org/get_started.html
-Modify method LibraryNameOrHandle of class LibClangMap with your clang.so path and with your plataform
5)LibGit2
Download Libgit2 through direct download from the browser[3] or cloning the repository through Git:
$sudo apt-get install git $git clone https://github.com/libgit2/libgit2.git
Compile LibGit2.
$mkdir build $cd build #only if you need install cmake $sudo apt-get install cmake #compile $cmake /pathlibgit2/libgit-2 $cmake --build pathbuild/build
6)Run TalkFFI
Modify in class TalkFFIExamples the methods libgit2 to link with my paths
– Inicialize LibClangMap in the workspace
LibClangMap initialize
-and generate code:
TalkFFIExamples libgit2Mapping
In Pharo If it’s ok, you view a similiar message 🙂
[0]https://rochiamaya.wordpress.com/2013/07/28/mi-proyect/
[1]http://www.pharo-project.org/pharo-download
August 1, 2013 at 8:51 am
Hi! This is cool. Could you show in a post some examples of the result you get after generating the code? How can a programmer use the generated library mapping?
Thanks!