Обсуждение: Compilate problems
I am working actually in an replication project. I need a trigger function but when I compile this, the C compilator
returnthe log message:
# cc -fpic -c main.c
In file included from /usr/include/postgresql/postgres.h:49,
from main.c:1:
/usr/include/postgresql/utils/elog.h:68:28: error: utils/errcodes.h: The file or directory does not exist
In file included from /usr/include/postgresql/8.3/server/funcapi.h:20,
from main.c:2:
/usr/include/postgresql/8.3/server/access/tupdesc.h:17:27: error: access/attnum.h: The file or directory does not exist
/usr/include/postgresql/8.3/server/access/tupdesc.h:18:34: error: catalog/pg_attribute.h: The file or directory does
notexist
/usr/include/postgresql/8.3/server/access/tupdesc.h:19:27: error: nodes/pg_list.h: No existe The file or directory does
notexist
In file included from /usr/include/postgresql/8.3/server/funcapi.h:20,
from main.c:2:
/usr/include/postgresql/8.3/server/access/tupdesc.h:24: error: expected specifier-qualifier-list before ‘AttrNumber’
/usr/include/postgresql/8.3/server/access/tupdesc.h:72: error: expected specifier-qualifier-list before
‘Form_pg_attribute’
/usr/include/postgresql/8.3/server/access/tupdesc.h:85: error: expected declaration specifiers or ‘...’ before
‘Form_pg_attribute’
.................
But the files exists in the indicated locations, any idea??
My plataform is Debian GNU/Linux, the headers files of postgresql-server-dev-8.3 are under
/usr/include/postgresql/8.3/server/,my haders files are:
#include <postgresql/8.3/server/postgres.h>
#include <postgresql/8.3/server/executor/spi.h>
#include <postgresql/8.3/server/commands/trigger.h>
Yadisnel Galvez Velazquez wrote: > I am working actually in an replication project. I need a trigger function but when I compile this, the C compilator returnthe log message: > > # cc -fpic -c main.c You're missing some -I directives (among other things). I suggest you compile this way: cc $(pg_config --cflags) -I$(pg_config --includedir)/server -c main.c You need pg_config to be in PATH for this to work. PS: I suggest you use the pgsql-es-ayuda list for spanish help. There's people from @uci.cu there too. -- Alvaro Herrera http://www.CommandPrompt.com/ PostgreSQL Replication, Consulting, Custom Development, 24x7 support
On Sun, Oct 04, 2009 at 01:07:54PM -0400, Yadisnel Galvez Velazquez wrote: > The problem is identical if I run this example: Please attach files instead of posting them in-line :) I've attached your example as a file. Please also to group-reply instead of just replying to the poster. Cheers, David -- David Fetter <david@fetter.org> http://fetter.org/ Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter Skype: davidfetter XMPP: david.fetter@gmail.com Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate
Вложения
The problem is identical if I run this example:
#include <postgresql/8.3/server/postgres.h>
#include <postgresql/8.3/server/executor/spi.h>
#include <postgresql/8.3/server/commands/trigger.h>
extern Datum trigf(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(trigf);
Datum
trigf(PG_FUNCTION_ARGS)
{
TriggerData *trigdata = (TriggerData *) fcinfo->context;
TupleDesc tupdesc;
HeapTuple rettuple;
char *when;
bool checknull = false;
bool isnull;
int ret, i;
/* make sure it's called as a trigger at all */
if (!CALLED_AS_TRIGGER(fcinfo))
elog(ERROR, "trigf: not called by trigger manager");
/* tuple to return to executor */
if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
rettuple = trigdata->tg_newtuple;
else
rettuple = trigdata->tg_trigtuple;
/* check for null values */
if (!TRIGGER_FIRED_BY_DELETE(trigdata->tg_event)
&& TRIGGER_FIRED_BEFORE(trigdata->tg_event))
checknull = true;
if (TRIGGER_FIRED_BEFORE(trigdata->tg_event))
when = "before";
else
when = "after ";
tupdesc = trigdata->tg_relation->rd_att;
/* connect to SPI manager */
if ((ret = SPI_connect()) < 0)
elog(INFO, "trigf (fired %s): SPI_connect returned %d", when, ret);
/* get number of rows in table */
ret = SPI_exec("SELECT count(*) FROM ttest", 0);
if (ret < 0)
elog(NOTICE, "trigf (fired %s): SPI_exec returned %d", when, ret);
/* count(*) returns int8, so be careful to convert */
i = DatumGetInt64(SPI_getbinval(SPI_tuptable->vals[0],
SPI_tuptable->tupdesc,
1,
&isnull));
elog (INFO, "trigf (fired %s): there are %d rows in ttest", when, i);
SPI_finish();
if (checknull)
{
SPI_getbinval(rettuple, tupdesc, 1, &isnull);
if (isnull)
rettuple = NULL;
}
return PointerGetDatum(rettuple);
}