Tuesday, July 15, 2008

To use UDF modules in ubuntu/linux

You must put full path to the UDF module when you declare the function
in my case
/usr/lib/firebird/2.1/UDF

otherwise you will get something like
"Invalid token. invalid request BLR at offset 63. function SUBSTR is not defined. module name or entrypoint could not be found."


--FBUDF_API int isLeapYear(const ISC_TIMESTAMP* v);
declare external function isLeapYear
timestamp
returns int by value
entry_point 'isLeapYear' module_name '/usr/lib/firebird/2.1/UDF/fbudf.so';
then it worked

select isLeapYear(hire_date) from EMPLOYEE


7 comments:

Radu said...

Marius,

have you tried to write an entire UDF under ubuntu with lazarus, and to register it? i'm struggling with this issue, and until now i have no results.for example

in project file exports Modulo;

pas file:

function Modulo(var i, j: Integer): Integer; cdecl; export;

function Mo(var i, j: Integer): Integer; cdecl; export;
begin
if (j = 0) then
result := -1
else
result := i mod j;
end;

ok, after this build shared object with ppc386 or fpc. if everything goes ok, then you have the '.so'. Now registering part is a little tricky because due to firebird.conf sometimes UdfAccess must be setted up to Restrict UDF. i'm struggling with this issue, and because the debugging is so hard, i can not figure out where is the real issue.

any idea is welcomed,

best regards,

Popa Adrian Marius said...

I will check to see how can be tested on my ubuntu box (free pascal udf and firebird 2.1)

ps:
on my system i have UdfAccess = Full

Popa Adrian Marius said...

my fpc compiler is crazzy , i have tried to compile it but it gives me error

Linking libtest.so
test.dpr(9) Error: Can't call the linker, switching to external linking
test.dpr(9) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/bin/ppcx64 returned an error exitcode (normal if you did not specify a source file to be compiled)

Popa Adrian Marius said...

i have tried to help you also solve this issue

http://tracker.firebirdsql.org/browse/CORE-2219

Popa Adrian Marius said...

How did you compiled from cmd line ?

Unknown said...

I ran into the same issue today with Ubuntu Server 10.04 and Firebird Classic 2.1.3.

I solved the issue by adding /usr/lib/firebird/2.1/lib and /usr/lib/firebird/2.1/UDF to the ld.conf cache.

Just create a file like /etc/ld.so.conf.d/firebird-udf.conf with a directory per line.

Then run # ldconfig

Now, the system will find libraries stored in these paths and you won't have to define your external functions using the full path.

Don't know if there is a better way to achieve that.

Rajiv said...

Thanks. I was facing the same problem on Ubuntu 10.4.

Changing directory within UDF declaration was difficult due to dependencies.