Re: Can I use extern "C" in an extension so I can use C++?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Isaac Morland <isaac(dot)morland(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Can I use extern "C" in an extension so I can use C++?
Date: 2020-07-05 22:07:07
Message-ID: 1313823.1593986827@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Isaac Morland <isaac(dot)morland(at)gmail(dot)com> writes:
> I'm writing a small extension, and I'm trying to use C++ constructs. I'm
> not actually doing anything that needs C++, but I *really* like declaring
> variables when I first initialize them (for example), and I also *really*
> like warning-free compiles.

Well, you could get that with -Wno-declaration-after-statement ...
but yeah, this is supposed to work, modulo all the caveats on the
page you already found.

> The C++ compiler is mangling the names so they aren't visible to the
> extension mechanism.

Something like the attached works for me; what problem are you having
*exactly*?

$ g++ -Wall -fno-strict-aliasing -fwrapv -g -O2 -D_GNU_SOURCE -c -I/home/postgres/pgsql/src/include -o test.o test.cpp
$ nm --ext --def test.o
0000000000000000 T Pg_magic_func
0000000000000010 T pg_finfo_silly_func
0000000000000020 T silly_func

regards, tom lane

Attachment Content-Type Size
test.cpp text/x-c 231 bytes

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Isaac Morland 2020-07-05 22:41:47 Re: Can I use extern "C" in an extension so I can use C++?
Previous Message Daniel Gustafsson 2020-07-05 21:28:11 Re: Binary support for pgoutput plugin