Thread: Triggers

Triggers

From
Alan Clucas
Date:
I am trying to create a simple trigger for postgres under cygwin in C. I
have followed the examples but I still can't get anything to load.

I am using current cygwin compiled postgresql with the sources installed
for their headerfiles, under Windows XP with SP1 (not that it should
matter). Postgresql thinks it's version 7.3.1-1.

Trying to compile one of the demonstration files (refint) in
C:\cygwin\usr\src\postgresql-7.3.1-1\contrib\spi\

postgres@alanc-xp /usr/src/postgresql-7.3.1-1/contrib/spi
$ gcc -I../../src/include -I../../src/backend   -O2 -Wall
-Wmissing-prototypes -O6 -fpic -I../../src/include   -c refint.c -o refint.o
cc1: warning: -fpic ignored for target (all code is position independent)

postgres@alanc-xp /usr/src/postgresql-7.3.1-1/contrib/spi
$ gcc -shared -o refint.so refint.o
refint.o(.text+0x302):refint.c: undefined reference to `_elog'
refint.o(.text+0x363):refint.c: undefined reference to `_elog'
refint.o(.text+0x389):refint.c: undefined reference to `_SPI_connect'
<SNIP - lots and lots of missing references>

As far as I can gather the undefined references shouldn't be resolved at
this point, instead they are resolved when the object is loaded into
postgres. So I have also tried loading the .o (unlinked files) to which
I get

jtms=# CREATE FUNCTION check_primary_key() RETURNS TRIGGER AS
'/usr/src/postgresql-7.3.1-1/contrib/spi/refint.o' LANGUAGE C;
ERROR:  Load of file /usr/src/postgresql-7.3.1-1/contrib/spi/refint.o
failed: dlopen: Win32 error 193

I presume this is because refint.o isn't a libary, so this is just me
being silly. I'm really stuck now, and the search engines are fed up
with me trying to find the answer.

Oh - and:

$ gcc -v
Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/3.2/specs
Configured with: /netrel/src/gcc-3.2-3/configure
--enable-languages=c,c++,f77,ja
va --enable-libgcj --enable-threads=posix --with-system-zlib
--enable-nls --with
out-included-gettext --enable-interpreter --disable-sjlj-exceptions
--disable-ve
rsion-specific-runtime-libs --enable-shared --build=i686-pc-linux
--host=i686-pc
-cygwin --target=i686-pc-cygwin --enable-haifa --prefix=/usr
--exec-prefix=/usr
--sysconfdir=/etc --libdir=/usr/lib --includedir=/nonexistent/include
--libexecd
ir=/usr/sbin
Thread model: posix
gcc version 3.2 20020927 (prerelease)

I have also tried with gcc2.95 of some variant or other. The above
procedure works fine under linux.

Any help gratefully received.

Alan


Re: Triggers

From
Jason Tishler
Date:
Alan,

On Fri, Feb 21, 2003 at 09:27:06AM +0000, Alan Clucas wrote:
> I am trying to create a simple trigger for postgres under cygwin in C.
> Trying to compile one of the demonstration files (refint) in
> C:\cygwin\usr\src\postgresql-7.3.1-1\contrib\spi\

Why not use make?

> postgres@alanc-xp /usr/src/postgresql-7.3.1-1/contrib/spi
> $ gcc -I../../src/include -I../../src/backend   -O2 -Wall
> -Wmissing-prototypes -O6 -fpic -I../../src/include   -c refint.c -o refint.o
> cc1: warning: -fpic ignored for target (all code is position independent)
>
> postgres@alanc-xp /usr/src/postgresql-7.3.1-1/contrib/spi
> $ gcc -shared -o refint.so refint.o
> refint.o(.text+0x302):refint.c: undefined reference to `_elog'
> refint.o(.text+0x363):refint.c: undefined reference to `_elog'
> refint.o(.text+0x389):refint.c: undefined reference to `_SPI_connect'
> <SNIP - lots and lots of missing references>

Instead of the above you would get the following:

    $ make -n refint.dll
    gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations  -DREFINT_VERBOSE -I. -I../../src/include   -c -o
refint.orefint.c 
    dlltool --export-all --output-def refint.def refint.o
    dllwrap -o refint.dll --def refint.def refint.o ../../src/utils/dllinit.o -L../../src/backend -lpostgres
    rm -f refint.def
    rm refint.o

> As far as I can gather the undefined references shouldn't be resolved
> at this point, instead they are resolved when the object is loaded
> into postgres.

No, this is Windows and not Unix.  Cygwin does a lot, but it can only do
so much...

Jason

--
PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers
Fingerprint: 7A73 1405 7F2B E669 C19D  8784 1AFD E4CC ECF4 8EF6