Node: Exporting GPC Libraries to Other Languages, Previous: Importing Libraries from Other Languages, Up: Other Languages

#### Exporting GPC Libraries to Other Languages

The `.o` files produced by GPC are in the same format as those of all other GNU compilers, so there is no problem in writing libraries for other languages in Pascal. To use them, you will need to write kind of interface – a header file in C. However there are some things to take into account, especially if your Pascal unit exports objects:

- By default, GPC capitalizes the first letter (only) of each identifier, so `procedure FooBAR` must be imported as `extern void Foobar()` from C.
- If you want to specify the external name explicitly, use `attribute`:

                procedure FooBAR; attribute (name = 'FooBAR');
                begin
                  WriteLn ('FooBAR')
                end;

  This one can be imported from C with `extern void FooBar()`.

- Objects are “records” internally. They have an implicit `vmt` field which contains a pointer to the “virtual method table”. This table is another record of the following structure:

                type
                  VMT = record
                    ObjectSize: PtrInt;     { Size of object in bytes }
                    NegObjectSize: PtrInt;  { Negated size }
                    Methods: array [1 .. n] of procedure;
                      { Pointers to the virtual methods. The entries are of the
                         repective procedure or function types. }
                  end;

  You can call a virtual method of an object from C if you explicitly declare this `struct` and explicitly dereference the `Fun` array. The VMT of an object `FooBAR` is an external (in C sense) variable `vmt_Foobar` internally.

- Methods of objects are named `Myobject_Mymethod` (with exactly two capital letters) internally.
- If you want to put a program in a library for some reason, and you want to give the `main` program an internal name different from `main`, call GPC with the command-line option `--gpc-main="GPCmain"` (see the previous subsection).