Re: C-Language function invocation from another one.

From: Ilya Urikh <ilya(dot)urikh(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: C-Language function invocation from another one.
Date: 2009-05-14 06:56:54
Message-ID: adf175f70905132356p2895160fg71d318593284b471@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Thanks! That's help.

When I compile functions in the same library they work fine. But if I put
one to another shared library function execution failed with error:
can't load library "/usr/lib/pgsql/calculateAccount.so":
/usr/lib/pgsql/calculateAccount.so: undefined symbol:
calculateAccountService

Details:
------------------------------------------------------
File calculateAccount.c is compiled to calculateAccount.so:

Datum calculateAccount(PG_FUNCTION_ARGS)
{
...
DirectFunctionCall3(calculateAccountService, accountId,
atoi(SPI_getvalue(tuple, tupdesc, 1)), startDate);

PG_RETURN_NULL();
}

-----------------------------------------------------
File calculateAccountService.c is compiled to calculateAccountService.so:

Datum calculateAccountService(PG_FUNCTION_ARGS)
{
...

PG_RETURN_VOID();
}

------------------------------------------
Define the functions to PostgreSQL

CREATE OR REPLACE FUNCTION calculateAccountService(integer, smallint, date)
RETURNS void AS
'calculateAccountService.so', 'calculateAccountService'
LANGUAGE C STRICT;

CREATE OR REPLACE FUNCTION calculateAccount(integer, date, date)
RETURNS void AS
'calculateAccount.so', 'calculateAccount'
LANGUAGE C STRICT;

----------------------------------------
Try to execute:
SELECT calculateAccount(2, '2008-02-23', '2009-04-13');

And receive Error message:
can't load library "/usr/lib/pgsql/calculateAccount.so":
/usr/lib/pgsql/calculateAccount.so: undefined symbol:
calculateAccountService

Thanks in advance,

Ilya Urikh.

On Thu, May 14, 2009 at 10:44 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Ilya Urikh <ilya(dot)urikh(at)gmail(dot)com> writes:
> > What is the best way to call C-Language function from another one?
>
> Try DirectFunctionCallN --- there are many examples in the source code.
>
> regards, tom lane
>

--
Best regards,
Ilya Urikh.

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Mark 2009-05-14 11:13:17 'Hot' backup of PostgreSQL dbases
Previous Message A. Kretschmer 2009-05-14 05:19:02 Re: update problem