[Lazarus] How to access C and C++ libraries?

Sven Barth pascaldragon at googlemail.com
Fri Mar 7 15:56:45 CET 2014


Am 07.03.2014 15:12, schrieb Daniel Gaspary:
> On Fri, Mar 7, 2014 at 6:38 AM, Sven Barth <pascaldragon at googlemail.com> wrote:
>> Am 07.03.2014 10:13, schrieb Danny Weldon:
>>>> You can't access a C++ API.
>>> Not yet.  But it is planned for the future:
>>>
>>>     http://freepascal.org/future.var
>>>     "Linking with C++ code"
>> And with quite some restrictions it already works, see
>> $fpc/tests/test/cg/tcppcl{1,2}.pp.
> Is this feature at trunk?
I haven't worked on it since some time, so the current state is even in 
2.6.0.
> Further examples of use.. ?
A cppclass is declared like this:

=== code begin ===

type
   TTest = cppclass external 'MyCLib' name 'Test' (TParent)
     procedure Test;
     class procedure StaticTest;
   end;

=== code end ===

Notes:
- if TParent is defined it needs to be a cppclass as well
- for sizeof to work correctly you need to specifiy the fields the same 
way as in C++ (though this might still be buggy)
- cppclass instances are not implicit pointers like classes, so you need 
to use "myvar^.Test" instead

Current restrictions:
- currently no namespaces supported
- currently no support for virtual metods (static methods work, instance 
methods *should* work)
- no support for construction/destruction yet (so you need to have the 
library instantiate the object)
- no support for multiple inheritance or virtual inheritance
- no support for operators (especially not the C++ specific ones)

In general this feature is experimental/in development, so your mileage 
may vary. Bug reports are welcome though :)

Regards,
Sven




More information about the Lazarus mailing list