Difference between revisions of "Creating bindings for C libraries"
Line 26: | Line 26: | ||
The C header files .h describes the interface of a C library. They are normally not provided with the library. You have to get the sources or the development package of the library. For example the C header files of the gtk libraries are in the package gtk+-devel. | The C header files .h describes the interface of a C library. They are normally not provided with the library. You have to get the sources or the development package of the library. For example the C header files of the gtk libraries are in the package gtk+-devel. | ||
+ | |||
+ | ==Example: MPICH2== | ||
+ | |||
+ | Download the mpich2-1.0.3.tar.gz from http://www-unix.mcs.anl.gov/mpi/mpich2/ and unpack them. The .h files are under mpich2-1.0.3/src/include. | ||
=Create a working directory and name your bindings= | =Create a working directory and name your bindings= |
Revision as of 23:39, 20 September 2006
Overview
This page describes how to create pascal bindings for C libraries. Normally Pascal can not use C libraries directly. You have to create for every C function, type, variable a pascal translation. There is the h2pas tool, which can automatically translate many common C things. And there is a GUI for Lazarus using h2pas and other tools to automate the creation, so that if the bindings needs to be updated you don't have to restart all over.
Work flow
- Fetch the C header files you want to translate.
- Create a working directory and give your bindings a name
- Create a new h2pas project with the h2pas wizard.
- add the .h files to the project
- setup the h2pas options
- run the wizard
- fix errors by adding text tools and run the wizard again
- when h2pas runs without errors, test compilation and add optional tools to beautify the output
- write some test programs to test your bindings
- publish your bindings on lazarus-ccr or Free Pascal
Install tools
The h2pas tool comes with every normal fpc installation.
Install the h2paswizard package in the Lazarus IDE. Go to "Components -> Configure installed packages ...", select from the right list the H2PasWizard package and click 'Install selection', then 'Save and rebuild IDE'. Restart the IDE and you get a new menu entry: Tools -> h2pas
Fetch C header files
The C header files .h describes the interface of a C library. They are normally not provided with the library. You have to get the sources or the development package of the library. For example the C header files of the gtk libraries are in the package gtk+-devel.
Example: MPICH2
Download the mpich2-1.0.3.tar.gz from http://www-unix.mcs.anl.gov/mpi/mpich2/ and unpack them. The .h files are under mpich2-1.0.3/src/include.
Create a working directory and name your bindings
Create a directory with a useful name. A name should not contain special characters, like spaces, umlaute, points or commas.