From: | Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> |
---|---|
To: | Anthony Rafael Sotolongo Leon <asotolongo(at)uci(dot)cu> |
Cc: | pgsql-es-ayuda <pgsql-es-ayuda(at)postgresql(dot)org> |
Subject: | Re: AYUDA con Programacion en C para PostgreSQL |
Date: | 2011-03-14 13:48:38 |
Message-ID: | 1300109790-sup-7115@alvh.no-ip.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-es-ayuda |
Excerpts from Anthony Rafael Sotolongo Leon's message of dom mar 13 14:18:11 -0300 2011:
> Hola a todos estoy tratando de iniciarme programando en C para PostgreSQL y para so estoy leyendo el manual de la 9.0 seccion 35.9. C-Language Functions , aqui les pongo el primer programa (test.c)
>
>
> #include "fmgr.h"
> #ifdef PG_MODULE_MAGIC
> PG_MODULE_MAGIC;
> #endif
Antes que eso debe ir
#include "postgres.h"
> int suma (int a, int b)
> {
> return a+b;
> }
Esta no es la forma de declarar una función en Postgres. Necesitas usar
las macros PG_FUNCTION_ARGS, PG_GETARG_INT32, y PG_RETURN_INT32. Mira
este artículo:
http://www.postgresql-es.org/node/217
> y lo compilo de modo siguiente
> gcc -I /usr/local/include -c test.c
> Y me da los siguientes errores (es como si la fmgr.h tuviera problemas) :
Además deberías usar pg_config para indicarle las opciones de
compilación. Normalmente debería bastar con la siguiente línea:
gcc $(pg_config --cflags) $(pg_config --includedir-server) -c test.c
Pero realmente, en vez de estar compilando a mano, lo más conveniente es
crear un Makefile muy simple, como este:
MODULE_big = test
OBJS = test.o
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
Luego escribes "make" y compila y crea una biblioteca, y con "make
install" la instala. Es mucho más simple.
--
Álvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2011-03-14 14:50:14 | Re: funcion y enable_sort,enable_seq_scan |
Previous Message | Jaime Casanova | 2011-03-14 04:50:15 | Re: AYUDA con Programacion en C para PostgreSQL |