Compiling/Loading C function

Started by Konstantinos Vassiliadisalmost 28 years ago1 messagesgeneral
Jump to latest
#1Konstantinos Vassiliadis
vassilik@p05.cs.man.ac.uk

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