Re: g++ not working for postgresql extension languages?

From: Lonnie Cumberland <lonnie_cumberland(at)yahoo(dot)com>
To: Lonnie Cumberland <lonnie_cumberland(at)yahoo(dot)com>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: g++ not working for postgresql extension languages?
Date: 2001-04-15 01:33:36
Message-ID: 20010415013336.75057.qmail@web12502.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces pgsql-sql

Thanks All,

It is now solved by using the "extern "C" {....} directive.

Thanks for all of the help..

Cheers :)

Lonnie
--- Lonnie Cumberland <lonnie_cumberland(at)yahoo(dot)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(at)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(at)Treazurac /test]# g++ -shared -o funcs.so funcs.o
>
> [root(at)Treazurac /test]# ls
>
> Makefile Makefile.global Makefile.port funcs.cc funcs.o funcs.so*
> funcs.sql
>
> [root(at)Treazurac /test]# pico -w funcs.sql
>
> [root(at)Treazurac /test]# psql -f funcs.sql -d trdata
> DROP
> CREATE
>
> [root(at)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(at)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(at)Treazurac /test]# gcc -shared -o funcs.so funcs.o
>
> [root(at)Treazurac /test]# psql -f funcs.sql -d trdata
> DROP
> CREATE
>
> [root(at)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(at)postgresql(dot)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/

In response to

Browse pgsql-interfaces by date

  From Date Subject
Next Message Lonnie Cumberland 2001-04-15 01:55:42 what about external libraries?
Previous Message Tom Lane 2001-04-15 01:08:17 Re: [SQL] g++ not working for postgresql extension languages?

Browse pgsql-sql by date

  From Date Subject
Next Message Poet/Joshua Drake 2001-04-15 06:01:47 Re: Same question about PostgreSql
Previous Message Tom Lane 2001-04-15 01:08:17 Re: [SQL] g++ not working for postgresql extension languages?