Difference between revisions of "Lazarus/FPC Libraries/es"

From Lazarus wiki
Jump to navigationJump to search
Line 46: Line 46:
 
===Windows===
 
===Windows===
  
Windows searches a library in the current directory, the system directory and the environment variable PATH.
+
Windows busca una librería en el directorio actual, en el directorio del sistema y fianlmente en las rutas de la variable de entorna PATH.
  
 
==ppumove, .ppu, .ppl==
 
==ppumove, .ppu, .ppl==

Revision as of 18:07, 27 May 2008

English (en) español (es) français (fr) 日本語 (ja) русский (ru)

Esta página describe las posibilidades de creación de librerias con Lazarus/FPC y cómo usarlas en proyectos y paquetes.

Tópicos relacionados

General

Enlace estático: FPC compila y enlaza por defecto los ejecutables estáticamente. Esto significa que instruye al enlazador para que ponga todos los ficheros objeto (.o) del proyecto y todos los paquetes en un gran ejecutable. Ventajas: no hay dependencias externas. Desventajas: No se comparte el código entre diferentes programas en la misma máquina. Y no se pueden cargar o descargar utilidades "conectables" (plugins)

Librerías dinámicas: La idea de la librería dinámica es compartir código entre programas, ahorrando memoria ocupada por el código, reduciendo el tiempo de iniciación requerido por las librerías y permitiendo utilidades "conectables". Las desventajas de las librerías dinámicas son: son más lentas en las librerías menos usadas, su estructura y funcionamiento interno son más complicados (esto es principalmente un problema para el compilador), su iniciación es diferente (ver más abajo) y compartir el código implica que las versiones del código en el sistema sean compatibles.

Sistemas Operativos

Librerías dinámicas:

Sistema Operativo Librería dinámica Librería estática
FreeBSD .so .a
MacOSX .dylib ?
Linux .so .a
Windows .dll .lib

FreeBSD

MacOSX

Linux

El nombre de fichero de una librería dinámica tiene siempre la forma 'lib'+nombrepaquete+'.so'+versión. Por ejemplo:libz.so.1 and libz.so.1.2.2.

Linux busca una librería en la ruta de la variable de entorno LD_LIBRARY_PATH, después en /lib, después en /usr/lib y finalmente en las rutas de /etc/ld.so.conf.

To share memory (GetMem/FreeMem, strings) with other libraries (not written in FPC) under Linux you should use the unit cmem. This unit must be added as the very first unit in the uses section of the project main source file (typically .lpr), so that its initialization section is called before any other unit can allocate memory.

Windows

Windows busca una librería en el directorio actual, en el directorio del sistema y fianlmente en las rutas de la variable de entorna PATH.

ppumove, .ppu, .ppl

FPC normally creates for every unit a .ppu and .o file. The .ppu file contains every important information of the .pas/.pp file (types, required filenames like the .o file), while the .o file contains the assembler code and the mangled names understood by the current system.

The ppumove tool included with every FPC installation, converts one or several .ppu and .o files into a dynamic library. It does this by calling the linker to gather all .o files into a .so (windows: .dll) file and removes the .o filename references from the .ppu file. These new .ppu files are normally called .ppl files.

For example:

You have the output directory of a package (where the .ppu files are):

 ppumove -o packagename -e ppl *.ppu

This will convert all .ppu files into .ppl files and creates a libpackagename.so (windows: packagename.dll). Note that under Linux the prefix 'lib' is always prepended.

This new library can already be used by other programming languages like C. Or by FPC programs by using the external modifiers. But the initialization/finalization sections must be called automatically. This includes the initialization/finalization of the heap manager. This means no strings or GetMem. Of course FPC programmers are spoiled and they can get more.

dlopen - loading a dynamic library

Loading a dynamic library is simple with the dlopen function of the unit dl.

ToDo: give an example

The main problem is to get the filename, which depends on the version and the operating system.

Initialization

Every unit can contain an initialization section. The order of the initialization sections depend on the uses sections of each unit.

How to initialize a dynamic library: ToDo

Finalization

Every unit can contain an finalization section. The order is the reverse order of the initialization sections.

Versions, Distribution

Libraries tend to grow and change over time. Adding new features is no problem, but removing a public method or changing its parameters makes the library incompatible. That means either an installed library (.so, .dll, .dylib) is replaced by a compatible one or a new library must be added to the system. That's why every library contains a version.

To load a dynamic library (dlopen of unit dl) the correct filename must be known. Under Linux this means, you have to know the version number.

ToDo: proposal how the IDE should create version numbers

See Also