Thread: Linking ECPG files to a C program

Linking ECPG files to a C program

From
Jim Parker
Date:
G'Day !

I have a very confusing problem.

I am trying to link files using a ECPG interface to a postgresql database
to a vector drawing program.

My test programs (when compiled by hand) work great, but when I use a
makefile to compile the modules and the regular C program, the linker gives
me undefined references to the ECPG routines.

I am using suffix rules in my Makefile as follows:

.pgc.c:ecpg -t $(PG_INC) $< $*.c

.c.o:$(CC) -c ($PG_INC) $(CFLAGS) $< -o $*.o

test_db: $(DB_OBJS) $(TEST_OBJS)$(CC) $(GTKLIB) $(LIBS) -o test_db $(DB_OBJS) $(TEST_OBJS)

Should I create a library to hold the ECPG routines ?  

Does anyone have any example code/Makefile I can look at ?

TIA

cheers,
Jim Parker



Re: Linking ECPG files to a C program

From
Antonio Sergio de Mello e Souza
Date:
  Jim Parker wrote:

>
>Should I create a library to hold the ECPG routines ?  
>
It is not necessary.

>
>Does anyone have any example code/Makefile I can look at ?
>
This is an example similar to the makefile that I use:


EC       = ecpg
CC       = gcc
INCPG    = /usr/local/pgsql/include   # Path for postgresql includes.
INCAPP   = ../h                       # Path for application-specific 
header.
INCSQL   = ../h                       # Path for host variables 
declarations header.
LIBPG    = /usr/local/pgsql/lib       # Path for ecpg libraries.
LIBSPG   = -lecpg -lpq                # Ecpg libraries.
CFLAGS   = -Wall -g -c

# I use the suffix '.ec' for ecpg source files instead of '.pgc'.

%.c : %.ec   $(EC) -t -I $(INCSQL) -o $@ $<

%.o : %.c   $(CC) $(CFLAGS) -I $(INCPG) -I $(INCAPP) -o $@ $<

% : %.o ;

.PHONY: all util clean

all: util program1 program2

util: util1.o util2.o util3.o

program1: program1.o util1.o util2.o   $(CC) -o $@ $^ -L $(LIBPG) $(LIBSPG)

program2: program2.o util2.o util3.o   $(CC) -o $@ $^ -L $(LIBPG) $(LIBSPG)

clean:   -rm -f *.o core


Regards,

Antonio Sergio






Re: Linking ECPG files to a C program

From
Jim Parker
Date:
G'Day !

Thanks, I modified my Makefile accordingly and it now works.

I wonder if it was the SUFFIX rules ... ?

cheers
Jim parker

On Wed, 06 Mar 2002, Antonio Sergio de Mello e Souza wrote:
> Date: Wed, 06 Mar 2002 10:39:42 -0300
> To: hopeye@cfl.rr.com
> From: Antonio Sergio de Mello e Souza <asergioz@bol.com.br>
> CC: pgsql-interfaces@postgresql.org
> Subject: Re: [INTERFACES] Linking ECPG files to a C program
> 
>   Jim Parker wrote:
> 
> >
> >Should I create a library to hold the ECPG routines ?  
> >
> It is not necessary.
> 
> >
> >Does anyone have any example code/Makefile I can look at ?
> >
> This is an example similar to the makefile that I use:
> 
> 
> EC       = ecpg
> CC       = gcc
> INCPG    = /usr/local/pgsql/include   # Path for postgresql includes.
> INCAPP   = ../h                       # Path for application-specific 
> header.
> INCSQL   = ../h                       # Path for host variables 
> declarations header.
> LIBPG    = /usr/local/pgsql/lib       # Path for ecpg libraries.
> LIBSPG   = -lecpg -lpq                # Ecpg libraries.
> CFLAGS   = -Wall -g -c
> 
> # I use the suffix '.ec' for ecpg source files instead of '.pgc'.
> 
> %.c : %.ec
>     $(EC) -t -I $(INCSQL) -o $@ $<
> 
> %.o : %.c
>     $(CC) $(CFLAGS) -I $(INCPG) -I $(INCAPP) -o $@ $<
> 
> % : %.o ;
> 
> ..PHONY: all util clean
> 
> all: util program1 program2
> 
> util: util1.o util2.o util3.o
> 
> program1: program1.o util1.o util2.o
>     $(CC) -o $@ $^ -L $(LIBPG) $(LIBSPG)
> 
> program2: program2.o util2.o util3.o
>     $(CC) -o $@ $^ -L $(LIBPG) $(LIBSPG)
> 
> clean:
>     -rm -f *.o core
> 
> 
> Regards,
> 
> Antonio Sergio
> 
> 
> 
>