Compiling/Loading C function - Mailing list pgsql-general

From Konstantinos Vassiliadis
Subject Compiling/Loading C function
Date
Msg-id Pine.LNX.3.95.980722133243.735B-100000@p05.cs.man.ac.uk
Whole thread Raw
List pgsql-general
Hello
I am desperately trying to use a type I have created. PostgreSQL runs
under SunOS 4.1.x. I followed the documentation's example on this platform
 %  cc -I$PGROOT/include -I$PGROOT/src/include -PIC -c phone.c
  gives too many errors in header files...........

Then, I used gcc (following documentation's example for Solaris !!)
 % gcc -I$PGROOT/include -I$PGROOT/src/include -fPIC -c phone.c
 % ld -Bdynamic -o phone.so phone.o
 Then from Linux client
 % psql test
 test=> CREATE FUNCTION phone_in(opaque)
        RETURNS phone
        AS '/home/postgres/linux/src/phone/phone.so'
        LANGUAGE 'c';

        CREATE FUNCTION phone_out(opaque)
        RETURNS opaque
        AS '/home/postgres/linux/src/phone/phone.so'
        LANGUAGE 'c';

        CREATE TYPE phone (
        internallength =8,
        input = phone_in,
        output = phone_out);

        CREATE TABLE test_phone (
        mynumber phone,
        hernumber phone);

        INSERT INTO test_phone VALUES ('01483-827294','0161-2242394');

At this point gives
ERROR:  Load of file /home/postgres/linux/src/phone/phone.so failed:
        ld.so: object could not be mapped
I then issue 'load' from prompt:
test=> load '/home/postgres/linux/src/phone/phone.so';
ERROR:  LOAD: could not open file /home/postgres/linux/src/phone/phone.so

Therefore I desperately ask:

a) Do I compile for the platform where Postgres runs? (may sound ignorant
but in fact it is my first real exposure to C compilers)

b) Do I use cc or gcc?

c) Could the options used in the compilation/linking process differ among
two cases even though Postgres runs on same plarform?

d) Do I need to use 'load' or is the function automatically loaded when
first called?

Thanks
Kostas


pgsql-general by date:

Previous
From: The Hermit Hacker
Date:
Subject: Re: [GENERAL] Re: [HACKERS] [Fwd: SGVLLUG Oracle and Informix on Linux]
Next
From: The Hermit Hacker
Date:
Subject: Re: [GENERAL] Re: [HACKERS] [Fwd: SGVLLUG Oracle and Informix on Linux]