Difference between revisions of "Creating bindings for C libraries"

From Lazarus wiki
Jump to navigationJump to search
Line 1: Line 1:
 
=Overview=
 
=Overview=
  
You have a C library (for example a .dll or .so) and you want to use it in your pascal program. You only found C header files (.h) and now you want to create one or more pascal units to access them.
+
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.
  
FPC can easily use C libraries. For example you only need to provide for every needed function a pascal function and add the 'external' modifier.
+
=Tools=
  
For small libraries this can be done manually, but for big libraries with hundreds or thousands of functions, constants, types and variables you should use tools like ''h2pas''.
+
Install the h2paswizard package in the Lazarus IDE. Go to

Revision as of 23:02, 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.

Tools

Install the h2paswizard package in the Lazarus IDE. Go to