Re: cpp Makefiles

From: Lonnie Cumberland <lonnie_cumberland(at)yahoo(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: cpp Makefiles
Date: 2001-04-15 00:53:26
Message-ID: 20010415005326.23512.qmail@web12503.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces pgsql-sql

Hello Peter,

I am in the process of downloading the new 7.1 PostgreSQL and will update my
system from the 7.03 version.

Actually there is not a problem in compiling the examples in the
interfaces/libpq++ directory and those work just fine.

I will try to explain the problem and the steps that I have taken to get that
problem generated in the hopes that it will help illuminate the error.

I have a simple test function:

-----------------------------------------------------------------------------

#include "postgres.h" // for variable length type

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#include <unistd.h> // for unix crypt function

text *
concat_text(text *arg1, text *arg2);

text *
concat_text(text *arg1, text *arg2)
{
int32 new_text_size = VARSIZE(arg1) + VARSIZE(arg2) - VARHDRSZ;
text *new_text = (text *) malloc(new_text_size);

memset((void *) new_text, 0, new_text_size);
VARSIZE(new_text) = new_text_size;
strncpy(VARDATA(new_text), VARDATA(arg1), VARSIZE(arg1)-VARHDRSZ);
strncat(VARDATA(new_text), VARDATA(arg2), VARSIZE(arg2)-VARHDRSZ);
return (new_text);
}


-------------------------------------------------------------------------

which I have saved as two different files for testing:

files: "funcs.c" and "funcs.cc"

load into the pgsql command interpreter the registration of this function:

"psql -f funcs.sql -d trdata"

the "funcs.sql" is simply:

------------------------------------------------------------------------------
DROP FUNCTION concat_text(text, text);
CREATE FUNCTION concat_text(text, text) RETURNS text
AS '/treazurac/funcs.so' LANGUAGE 'c';
------------------------------------------------------------------------------

Now then, the two different outcomes are:

Outcome A:
1. I do a "make" with just the "funcs.c" program in the directory and the
"funcs.so" is created just fine.

I get the following messages:
-------------------------------------------------------------------------
[root(at)Treazurac /test]# make
gcc -I./include -I./backend -O2 -Wall -Wmissing-prototypes
-Wmissing-declarations -I/usr/include/pgsql -I/usr/include -fpic -c -o
funcs.o funcs.c
gcc -shared -o funcs.so funcs.o
rm funcs.o
----------------------------------------------------------------------------

2. Enter the "psql trdata"

3. do a "select concat_text('a','b');

and the result is a string "ab" just as expected.

Outcome B:
1. I do a "make" with just the "funcs.cc".

This time the g++ compiler is called and I get:
-------------------------------------------------------------------------
g++ -c -o funcs.o funcs.cc
funcs.cc:23: postgres.h: No such file or directory
make: *** [funcs.o] Error 1
--------------------------------------------------------------------------

I have tried adjusting the INCLUDES and LIB paths but is seems that there is
some other things going on in the Makefile, Makefile.global, or Makefile.port
because I cannot simply enter the same "gcc" line to get a usable "funcs.so".

The reason that I need this to work is because I will be adding some c++
functions to the "funcs.cc" file and also need to be able to link in those
libraries as well.

Cheers,
Lonnie

__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/

In response to

Browse pgsql-interfaces by date

  From Date Subject
Next Message Giles Lean 2001-04-15 00:59:26 Re: DBD::Pg 0.96 and DBI 1.15 ignoring username and password
Previous Message Lonnie Cumberland 2001-04-15 00:46:15 g++ not working for postgresql extension languages?

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2001-04-15 01:08:17 Re: [SQL] g++ not working for postgresql extension languages?
Previous Message Tom Lane 2001-04-15 00:50:52 Re: Full outer join