pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedg++ not working for postgresql extension languages?
6+ messages / 4 participants
[nested] [flat]
* g++ not working for postgresql extension languages?
@ 2001-04-15 00:46 Lonnie Cumberland <lonnie_cumberland@yahoo.com>
2001-04-15 01:08 ` Re: [SQL] g++ not working for postgresql extension languages? Tom Lane <tgl@sss.pgh.pa.us>
2001-04-15 01:33 ` Re: g++ not working for postgresql extension languages? Lonnie Cumberland <lonnie_cumberland@yahoo.com>
2001-04-15 16:10 ` Re: [SQL] g++ not working for postgresql extension languages? Stephen Jackson <Stephen.Jackson@panting-deer.org.uk>
0 siblings, 3 replies; 6+ messages in thread
From: Lonnie Cumberland @ 2001-04-15 00:46 UTC (permalink / raw)
To: Peter Eisentraut <peter_e@gmx.net>; +Cc: pgsql-interfaces
Hi All again,
One more thing that I have tried.
If I now do a similar thing as in my previous message with the "funcs.c" file,
but this time with the "funcs.cc" file then I can get:
-------------------------------------------------------------------------
[root@Treazurac /test]# g++ -I./include -I./backend -O2 -Wall
-Wmissing-prototypes -Wmissing-declarations -I/usr/include/pgsql -I/usr/include
-fpic -c -o funcs.o funcs.cc
[root@Treazurac /test]# g++ -shared -o funcs.so funcs.o
[root@Treazurac /test]# ls
Makefile Makefile.global Makefile.port funcs.cc funcs.o funcs.so*
funcs.sql
[root@Treazurac /test]# pico -w funcs.sql
[root@Treazurac /test]# psql -f funcs.sql -d trdata
DROP
CREATE
[root@Treazurac /test]# psql trdata
Welcome to psql, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit
trdata=# select concat_text('a','b');
ERROR: Can't find function concat_text in file /test/funcs.so
trdata=#
--------------------------------------------------------------------------
And although I should not be running as "root", this is a test machine and it
is ok for the time being.
If I do the same thing as above, but using the "funcs.c" file (which is the
exact same file just renamed)
---------------------------------------------------------------------------
funcs.c and funcs.cc
-------------------------
#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);
}
--------------------------------------------------------------------------
with funcs.sql
------------------
DROP FUNCTION concat_text(text, text);
CREATE FUNCTION concat_text(text, text) RETURNS text
AS '/test/funcs.so' LANGUAGE 'c';
----------------------------------------------------------------------------
With the "funcs.c" file in place I get:
-----------------------------------------------------------------------------
[root@Treazurac /test]# 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
[root@Treazurac /test]# gcc -shared -o funcs.so funcs.o
[root@Treazurac /test]# psql -f funcs.sql -d trdata
DROP
CREATE
[root@Treazurac /test]# psql trdata
Welcome to psql, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit
trdata=# select concat_text('a','b');
concat_text
-------------
ab
(1 row)
trdata=#
-----------------------------------------------------------------------------
so now I do not understand why the "gcc" version works and the "g++" version
does not?
Just a side note in that I can easliy compile c++ the examples in the
interfaces/libpq++ directory without any problems so that this is very strange
to me.
I really need the "g++" version to work correctly as well?
Any ideas anyone?
Cheers
Lonnie
__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [SQL] g++ not working for postgresql extension languages?
2001-04-15 00:46 g++ not working for postgresql extension languages? Lonnie Cumberland <lonnie_cumberland@yahoo.com>
@ 2001-04-15 01:08 ` Tom Lane <tgl@sss.pgh.pa.us>
2 siblings, 0 replies; 6+ messages in thread
From: Tom Lane @ 2001-04-15 01:08 UTC (permalink / raw)
To: Lonnie Cumberland <lonnie_cumberland@yahoo.com>; +Cc: Peter Eisentraut <peter_e@gmx.net>; pgsql-interfaces
Lonnie Cumberland <lonnie_cumberland@yahoo.com> writes:
> so now I do not understand why the "gcc" version works and the "g++" version
> does not?
You need to say extern "C" to persuade a C++ compiler to compile a
function as something that can be called from plain C. They are not
the same language. See your C++ documentation for more info.
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: g++ not working for postgresql extension languages?
2001-04-15 00:46 g++ not working for postgresql extension languages? Lonnie Cumberland <lonnie_cumberland@yahoo.com>
@ 2001-04-15 01:33 ` Lonnie Cumberland <lonnie_cumberland@yahoo.com>
2 siblings, 0 replies; 6+ messages in thread
From: Lonnie Cumberland @ 2001-04-15 01:33 UTC (permalink / raw)
To: Lonnie Cumberland <lonnie_cumberland@yahoo.com>; +Cc: pgsql-interfaces
Thanks All,
It is now solved by using the "extern "C" {....} directive.
Thanks for all of the help..
Cheers :)
Lonnie
--- Lonnie Cumberland <lonnie_cumberland@yahoo.com> wrote:
> Hi All again,
>
> One more thing that I have tried.
>
> If I now do a similar thing as in my previous message with the "funcs.c"
> file,
> but this time with the "funcs.cc" file then I can get:
>
> -------------------------------------------------------------------------
> [root@Treazurac /test]# g++ -I./include -I./backend -O2 -Wall
> -Wmissing-prototypes -Wmissing-declarations -I/usr/include/pgsql
> -I/usr/include
> -fpic -c -o funcs.o funcs.cc
>
> [root@Treazurac /test]# g++ -shared -o funcs.so funcs.o
>
> [root@Treazurac /test]# ls
>
> Makefile Makefile.global Makefile.port funcs.cc funcs.o funcs.so*
> funcs.sql
>
> [root@Treazurac /test]# pico -w funcs.sql
>
> [root@Treazurac /test]# psql -f funcs.sql -d trdata
> DROP
> CREATE
>
> [root@Treazurac /test]# psql trdata
> Welcome to psql, the PostgreSQL interactive terminal.
>
> Type: \copyright for distribution terms
> \h for help with SQL commands
> \? for help on internal slash commands
> \g or terminate with semicolon to execute query
> \q to quit
>
> trdata=# select concat_text('a','b');
> ERROR: Can't find function concat_text in file /test/funcs.so
> trdata=#
> --------------------------------------------------------------------------
>
> And although I should not be running as "root", this is a test machine and it
> is ok for the time being.
>
> If I do the same thing as above, but using the "funcs.c" file (which is the
> exact same file just renamed)
> ---------------------------------------------------------------------------
> funcs.c and funcs.cc
> -------------------------
> #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);
> }
> --------------------------------------------------------------------------
>
> with funcs.sql
> ------------------
> DROP FUNCTION concat_text(text, text);
> CREATE FUNCTION concat_text(text, text) RETURNS text
> AS '/test/funcs.so' LANGUAGE 'c';
> ----------------------------------------------------------------------------
>
> With the "funcs.c" file in place I get:
> -----------------------------------------------------------------------------
> [root@Treazurac /test]# 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
>
> [root@Treazurac /test]# gcc -shared -o funcs.so funcs.o
>
> [root@Treazurac /test]# psql -f funcs.sql -d trdata
> DROP
> CREATE
>
> [root@Treazurac /test]# psql trdata
> Welcome to psql, the PostgreSQL interactive terminal.
>
> Type: \copyright for distribution terms
> \h for help with SQL commands
> \? for help on internal slash commands
> \g or terminate with semicolon to execute query
> \q to quit
>
> trdata=# select concat_text('a','b');
> concat_text
> -------------
> ab
> (1 row)
>
> trdata=#
> -----------------------------------------------------------------------------
>
> so now I do not understand why the "gcc" version works and the "g++" version
> does not?
>
> Just a side note in that I can easliy compile c++ the examples in the
> interfaces/libpq++ directory without any problems so that this is very
> strange
> to me.
>
> I really need the "g++" version to work correctly as well?
>
> Any ideas anyone?
>
> Cheers
> Lonnie
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail.
> http://personal.mail.yahoo.com/
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [SQL] g++ not working for postgresql extension languages?
2001-04-15 00:46 g++ not working for postgresql extension languages? Lonnie Cumberland <lonnie_cumberland@yahoo.com>
@ 2001-04-15 16:10 ` Stephen Jackson <Stephen.Jackson@panting-deer.org.uk>
2001-04-15 18:20 ` Re: Re: [SQL] g++ not working for postgresql extension languages? Lonnie Cumberland <lonnie_cumberland@yahoo.com>
2 siblings, 1 reply; 6+ messages in thread
From: Stephen Jackson @ 2001-04-15 16:10 UTC (permalink / raw)
To: Lonnie Cumberland <lonnie_cumberland@yahoo.com>; +Cc: pgsql-interfaces
Lonnie,
C++ uses "name mangling" to permit overloading of functions. Therefore
your function concat_text() ends up with a very different name. You can
probably get round this as follows:
#ifdef __cplusplus
extern "C" {
#endif
text *
concat_text(text *arg1, text *arg2);
#ifdef __cplusplus
}
#endif
This tells the C++ compiler that concat_text is a "C" name - so don't do
name mangling. This is a common technique for making C++ code callable
from C, although I haven't used it in the specific context you are
using.
Hope this helps,
Stephen Jackson
Home: Stephen.Jackson@panting-deer.org.uk www.panting-deer.org.uk
Work: Stephen.Jackson@looksystems.co.uk www.looksystems.co.uk
Lonnie Cumberland wrote:
>
> Hi All again,
>
> One more thing that I have tried.
>
> If I now do a similar thing as in my previous message with the "funcs.c" file,
> but this time with the "funcs.cc" file then I can get:
>
[snip]
>
> trdata=# select concat_text('a','b');
> ERROR: Can't find function concat_text in file /test/funcs.so
> trdata=#
> --------------------------------------------------------------------------
>
[snip]
>
> text *
> concat_text(text *arg1, text *arg2);
>
[snip]
> so now I do not understand why the "gcc" version works and the "g++" version
> does not?
>
> Just a side note in that I can easliy compile c++ the examples in the
> interfaces/libpq++ directory without any problems so that this is very strange
> to me.
>
> I really need the "g++" version to work correctly as well?
>
> Any ideas anyone?
>
> Cheers
> Lonnie
>
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Re: [SQL] g++ not working for postgresql extension languages?
2001-04-15 00:46 g++ not working for postgresql extension languages? Lonnie Cumberland <lonnie_cumberland@yahoo.com>
2001-04-15 16:10 ` Re: [SQL] g++ not working for postgresql extension languages? Stephen Jackson <Stephen.Jackson@panting-deer.org.uk>
@ 2001-04-15 18:20 ` Lonnie Cumberland <lonnie_cumberland@yahoo.com>
2001-04-15 19:52 ` Re: Re: [SQL] g++ not working for postgresql extension languages? Peter Eisentraut <peter_e@gmx.net>
0 siblings, 1 reply; 6+ messages in thread
From: Lonnie Cumberland @ 2001-04-15 18:20 UTC (permalink / raw)
To: Stephen Jackson <Stephen.Jackson@panting-deer.org.uk>; +Cc: pgsql-interfaces
Hello All,
I have gotten the EXTERN "C" statement to work with the simple test c++
functions, but I cannot get it to work with the my actual crypto4.0 c++ sources
which I am able to compile all together into a single funcs.so file.
I am getting no errors but when I go into the "psql trdata" and try the same
test then I get this error:
[root@Treazurac /test]# psql trdata
Welcome to psql, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit
trdata=# select concat_text('a','d');
ERROR: Load of file /test/trfuncs.so failed: /test/trfuncs.so: undefined
symbol: MemoryContextAlloc__FP17MemoryContextDataUi
-----------------------------------------------------------------------------
I do not know what is going on here because I did a simple test without my
cyrpto4.0 c++ files and using 3 different copies of concat_text(),
concat1_text() and concat2_text() which compiled and even ran fine.
now when I put in my other sources which compile correctly outside of
Postgresql, I get the above error.
I have zipped up the test files and will send them to someone if you would like
to take a quick look. Just let me know as I am at a loss as to why PostgreSQL
is having som much trouble with this C++ interface.
Cheers
Lonnie
--- Stephen Jackson <Stephen.Jackson@panting-deer.org.uk> wrote:
> Lonnie,
>
> C++ uses "name mangling" to permit overloading of functions. Therefore
> your function concat_text() ends up with a very different name. You can
> probably get round this as follows:
>
> #ifdef __cplusplus
> extern "C" {
> #endif
> text *
> concat_text(text *arg1, text *arg2);
> #ifdef __cplusplus
> }
> #endif
>
> This tells the C++ compiler that concat_text is a "C" name - so don't do
> name mangling. This is a common technique for making C++ code callable
> from C, although I haven't used it in the specific context you are
> using.
>
> Hope this helps,
>
> Stephen Jackson
> Home: Stephen.Jackson@panting-deer.org.uk www.panting-deer.org.uk
> Work: Stephen.Jackson@looksystems.co.uk www.looksystems.co.uk
>
> Lonnie Cumberland wrote:
> >
> > Hi All again,
> >
> > One more thing that I have tried.
> >
> > If I now do a similar thing as in my previous message with the "funcs.c"
> file,
> > but this time with the "funcs.cc" file then I can get:
> >
>
> [snip]
>
> >
> > trdata=# select concat_text('a','b');
> > ERROR: Can't find function concat_text in file /test/funcs.so
> > trdata=#
> > --------------------------------------------------------------------------
> >
>
> [snip]
>
> >
> > text *
> > concat_text(text *arg1, text *arg2);
> >
>
> [snip]
>
> > so now I do not understand why the "gcc" version works and the "g++"
> version
> > does not?
> >
> > Just a side note in that I can easliy compile c++ the examples in the
> > interfaces/libpq++ directory without any problems so that this is very
> strange
> > to me.
> >
> > I really need the "g++" version to work correctly as well?
> >
> > Any ideas anyone?
> >
> > Cheers
> > Lonnie
> >
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Re: [SQL] g++ not working for postgresql extension languages?
2001-04-15 00:46 g++ not working for postgresql extension languages? Lonnie Cumberland <lonnie_cumberland@yahoo.com>
2001-04-15 16:10 ` Re: [SQL] g++ not working for postgresql extension languages? Stephen Jackson <Stephen.Jackson@panting-deer.org.uk>
2001-04-15 18:20 ` Re: Re: [SQL] g++ not working for postgresql extension languages? Lonnie Cumberland <lonnie_cumberland@yahoo.com>
@ 2001-04-15 19:52 ` Peter Eisentraut <peter_e@gmx.net>
0 siblings, 0 replies; 6+ messages in thread
From: Peter Eisentraut @ 2001-04-15 19:52 UTC (permalink / raw)
To: Lonnie Cumberland <lonnie_cumberland@yahoo.com>; +Cc: Stephen Jackson <Stephen.Jackson@panting-deer.org.uk>; pgsql-interfaces
Lonnie Cumberland writes:
> trdata=# select concat_text('a','d');
> ERROR: Load of file /test/trfuncs.so failed: /test/trfuncs.so: undefined
> symbol: MemoryContextAlloc__FP17MemoryContextDataUi
Name mangling at its finest. You need to put extern "C" around all
#include's of PostgreSQL header files as well.
--
Peter Eisentraut peter_e@gmx.net http://funkturm.homeip.net/~peter
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2001-04-15 19:52 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-04-15 00:46 g++ not working for postgresql extension languages? Lonnie Cumberland <lonnie_cumberland@yahoo.com>
2001-04-15 01:08 ` Tom Lane <tgl@sss.pgh.pa.us>
2001-04-15 01:33 ` Lonnie Cumberland <lonnie_cumberland@yahoo.com>
2001-04-15 16:10 ` Stephen Jackson <Stephen.Jackson@panting-deer.org.uk>
2001-04-15 18:20 ` Lonnie Cumberland <lonnie_cumberland@yahoo.com>
2001-04-15 19:52 ` Peter Eisentraut <peter_e@gmx.net>
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