Re: Compiling "C" Functions

From: Louis-David Mitterrand <cunctator(at)apartia(dot)ch>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Compiling "C" Functions
Date: 2001-02-27 20:40:08
Message-ID: 20010227214008.A493@apartia.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thu, Dec 28, 2000 at 09:36:57AM -0500, Ron Peterson wrote:
> Tulio Oliveira wrote:
> >
> > I appreciate any "C" Function complete samples, including de command
> > line for
> > the compiler.
>
> I've attached a generic GNU make snippet for compiling .so files.
> Adjust to suite your tastes. Like my math textbooks used to say
> "writing the C code is trivial, and is left as an excercise for the
> reader." ;)
>
> CC = /usr/bin/gcc
> TARGET = debug
> #TARGET = final
> DFLAGS = -Wall -g
> FFLAGS = -Wall -O2
> SFLAGS = -fpic -shared
> MYINCLUDES = -I/usr/local/include
> -I/usr/local/src/postgresql/src/include -I/usr/local/postgresql/include
> MYLIBS = -L/usr/local/lib -L/usr/local/postgresql/lib -lpq
>
> ifeq ($(TARGET),final)
> MYCFLAGS = $(FFLAGS)
> else
> MYCFLAGS = $(DFLAGS)
> endif
>
> %.so:
> $(CC) $(MYCFLAGS) $(MYINCLUDES) $(MYLIBS) $(*F).c -c -o $(*F).o
> $(CC) $(SFLAGS) $(*F).o -o $(*F).so
> [ -d $(TARGET) ] || mkdir $(TARGET)
> mv $(*F).so $(TARGET)
> rm *.o

Or using implicit rules, only type "make my_file.so":

INCLUDES = -I /usr/include/postgresql
CFLAGS = -g -Wall $(INCLUDES) -fPIC

%.so: %.o
ld -shared -soname $@ -o $@ $< $(LIBS)

--
THERAMENE: Elle veut quelque temps douter de son malheur,
Et ne connaissant plus ce hros qu'elle adore,
Elle voit Hippolyte et le demande encore.
(Phdre, J-B Racine, acte 5, scne 6)

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tubagus Nizomi 2001-02-28 01:55:58 Error ??
Previous Message Tom Lane 2001-02-27 19:01:45 Re: Urgent help