pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
cpp Makefiles
4+ messages / 2 participants
[nested] [flat]

* cpp Makefiles
@ 2001-04-14 18:00 Lonnie Cumberland <lonnie_cumberland@yahoo.com>
  2001-04-14 22:29 ` Re: cpp Makefiles Peter Eisentraut <peter_e@gmx.net>
  0 siblings, 1 reply; 4+ messages in thread

From: Lonnie Cumberland @ 2001-04-14 18:00 UTC (permalink / raw)
  To: pgsql-interfaces

Hello All,

I have now been able to compile the complex.c functions and test them out with
no problems.

I made a copy of the Makefile, Makefile.global, and Makefile.port (Linux) from
the tutorial directory and made a simple modification for the paths. Now the
'c" files compile up just fine.

The problem is that this set up will not work if I make some C++ files. I think
that there is something wrong in one of the above makefiles for the g++
compiler and the needed options, but do not know where to find it.

I also need to link in some other libraries like "libfile.a" that I have for
some of the functions that will be placed in my pgSQL interface but do not know
where to add these library files so that the generated "file.so" can use them.

does someone have a simple Makefile that will allow me to compile up C++
functions and either link in the libfile.a files or could please tell me how to
make libfile.so out of them?

Cheers,
Lonnie
  

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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: cpp Makefiles
  2001-04-14 18:00 cpp Makefiles Lonnie Cumberland <lonnie_cumberland@yahoo.com>
@ 2001-04-14 22:29 ` Peter Eisentraut <peter_e@gmx.net>
  2001-04-15 00:23   ` Re: cpp Makefiles Lonnie Cumberland <lonnie_cumberland@yahoo.com>
  2001-04-15 00:53   ` Re: cpp Makefiles Lonnie Cumberland <lonnie_cumberland@yahoo.com>
  0 siblings, 2 replies; 4+ messages in thread

From: Peter Eisentraut @ 2001-04-14 22:29 UTC (permalink / raw)
  To: Lonnie Cumberland <lonnie_cumberland@yahoo.com>; +Cc: pgsql-interfaces

Lonnie Cumberland writes:

> does someone have a simple Makefile that will allow me to compile up C++
> functions and either link in the libfile.a files or could please tell me how to
> make libfile.so out of them?

There is no simple Makefile to do that, that's the problem.  If you need
help with your particular setup you should show in detail what you already
have and precisely what problem occurred.  If you're using the makefiles
from the PostgreSQL tree, I suggest you update to 7.1 and look into
src/interfaces/libpq++ for an example.  Also make sure your functions are
using C linkage (extern "C"), otherwise PostgreSQL won't find them.  And
avoid static constructors.  In general, C++ shared libraries are a complex
area that is hard to get right.

-- 
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: cpp Makefiles
  2001-04-14 18:00 cpp Makefiles Lonnie Cumberland <lonnie_cumberland@yahoo.com>
  2001-04-14 22:29 ` Re: cpp Makefiles Peter Eisentraut <peter_e@gmx.net>
@ 2001-04-15 00:23   ` Lonnie Cumberland <lonnie_cumberland@yahoo.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Lonnie Cumberland @ 2001-04-15 00:23 UTC (permalink / raw)
  To: Peter Eisentraut <peter_e@gmx.net>; +Cc: pgsql-interfaces

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@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/



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: cpp Makefiles
  2001-04-14 18:00 cpp Makefiles Lonnie Cumberland <lonnie_cumberland@yahoo.com>
  2001-04-14 22:29 ` Re: cpp Makefiles Peter Eisentraut <peter_e@gmx.net>
@ 2001-04-15 00:53   ` Lonnie Cumberland <lonnie_cumberland@yahoo.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Lonnie Cumberland @ 2001-04-15 00:53 UTC (permalink / raw)
  To: Peter Eisentraut <peter_e@gmx.net>; +Cc: pgsql-interfaces

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@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/



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2001-04-15 00:53 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-04-14 18:00 cpp Makefiles Lonnie Cumberland <lonnie_cumberland@yahoo.com>
2001-04-14 22:29 ` Peter Eisentraut <peter_e@gmx.net>
2001-04-15 00:23   ` Lonnie Cumberland <lonnie_cumberland@yahoo.com>
2001-04-15 00:53   ` Lonnie Cumberland <lonnie_cumberland@yahoo.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox