Homunculus Reticulli
Homunculus Reticulli

Reputation: 68426

What is wrong with this Makefile? (header files not found)

I am modifying an old makefile in order to build a C extension for postgreSQL. The Makefile currently looks like this:

PGLIB = /usr/lib/postgresql/8.4/lib
PQINC = /usr/include/postgresql/8.4/server        
CC=gcc

override CFLAGS+= $(CFLAGS_SL) -DPG_AGGREGATE 

SHLIB = pg_myextlib

SRC =  foo.c \
       foobar.c

OBJS = foo.o \       
       foobar.o

all: $(OBJS)
    $(CC) -shared -o $(SHLIB)$(DLSUFFIX) $(OBJS) -I$(PQINC)
    cp *.so $(PGLIB)

clean:
    rm -f $(SHLIB) $(OBJS) 

The error I get when I run make is:

common.h:58:22: error: postgres.h: No such file or directory

Which suggests that the include path is not being added (the file exists in $PQINC). Its a long time since I wrote the Makefile - and I haven't written many since. As an aside, I am pretty sure that 'shared' is not the gcc flag to build shared libs on Ubuntu (my current dev box) - I think the flag should be 'fPIC' - can someone confirm this?

I am runing gcc v4.4.3 on Ubuntu 10.0.4 and compiling for use with PG 8.4

Upvotes: 2

Views: 10585

Answers (3)

Joseph Quinsey
Joseph Quinsey

Reputation: 9962

You seem to be using the default rules to build foo.o from foo.c, which doesn't have your -I. Try adding the following rule to your Makefile:

.c.o:
        $(CC) $(CFLAGS) -c $< -o $@ -I$(PQINC)

Upvotes: 1

vhallac
vhallac

Reputation: 13907

Try moving the -I$(PQINC) from target all to the end of line that starts with override CFLAGS.

Upvotes: 3

paxdiablo
paxdiablo

Reputation: 881523

Placing -Isomething on the compiler line which turns object files, like those in $(OBJS), into executable will have no effect whatsoever.

You need to do it when you compile the source files.

Since your makefile doesn't explicitly show the rule for processing source files, it may well be using a default one, which is incredibly unlikely to know about PQINC.

Upvotes: 3

Related Questions