[fpc-pascal]UDF + FreePascal + Firebird 1.5

Michael.VanCanneyt at Wisa.be Michael.VanCanneyt at Wisa.be
Sat Jul 24 18:44:18 CEST 2004


On Sat, 24 Jul 2004, Guto wrote:

> I tried with both, but I get the same error...

Nevertheless, the library can be loaded and used without problems by
an FPC program, I tested this:

program testee;

function intmax (A,B : integer): integer; stdcall; external 'libteste' name
'intmax';

begin
  Writeln('Intmax 1,2 : ',intmax(1,2));
end.

And it correctly prints 2.

So the error must be in Firebird somewhere. 

- I am confused about the changing of owner and permissions. Have you tried
  changing it to root, with permissions 755 ?

- About calling conventions:
  Firebird will definitely expect 'cdecl' on Linux, but 'stdcall' on Windows.

A warning: 'integer' in standard FPC mode is 2 bytes, not 4, which is what 
Firebird expects. I suggest you add a {$mode objfpc} at the start of your
code, which will make integer 4 bytes.

> > > mv libteste.so /usr/local/firebird/UDF/
> > >
> > > I changed permissions:
> > > cd /usr/local/firebird/UDF
> > > chown firebird:firebird libteste.so
> > > chmod 550 libteste.so
> > >
> > > I declared UDF:
> > >

This is the mistake you made:

DECLARE EXTERNAL FUNCTION INTMAX
  INTEGER,
  INTEGER
RETURNS INTEGER BY VALUE
ENTRY_POINT 'intmax' MODULE_NAME 'libteste';

You must explicitly add the 'lib'; firebird does not add it itself. Look at
the standard libraries, they also miss the 'lib' prefix.

if you change it to the above, (with calling convention cdecl) it works correctly.

Michael.

> > >
> > > I test it:
> > > select intmax(1,2) from rdb$database;
> > >
> > > And I got this error message:
> > > Invalid token.
> > > invalid request BLR at offset 60.
> > > function INTMAX is not defined.
> > > module name or entrypoint could not be found.
> > >
> > > Does anyone have any ideas?
> > >
> > 
> > Are you 100% sure it doesn't have to be cdecl; instead of stdcall on *nix?
> > 
> > _______________________________________________
> > fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> > http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> > 
> 
> 
> -- 
> Guto
> 
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> 




More information about the fpc-pascal mailing list