Re: g++ not working for postgresql extension languages? - Mailing list pgsql-bugs

From Thomas Lockhart
Subject Re: g++ not working for postgresql extension languages?
Date
Msg-id 3AD93A5A.D40EEFC2@alumni.caltech.edu
Whole thread Raw
In response to g++ not working for postgresql extension languages?  (Lonnie Cumberland <lonnie_cumberland@yahoo.com>)
List pgsql-bugs
> Any ideas on how to fix this so that I can use c++ functions compiled with g++
> in the PL/pgSQL extensions?

To implement function overloading, g++ (and other c++ compilers) use
"name mangling" to allow functions and methods with the same name but
with different arguments to be handled by standard linkers. It is a
clever scheme, but it does require that you explicitly identify
functions or methods written in C++ which you will be calling from C or
from other non-C++ languages.

You will want to do this anyway (even if you could instead figure out
what the mangled name looks like and declare that as the entry point)
because C++ has features and conventions to implement, for example,
exceptions which are incompatible with the calling C code.

You make them compatible by surrounding the declaration of your C++
function with the following:

extern "C" {
 <your function prototype here...>
}

The actual implementation does not have to have this, only your
prototype declaration. The function or method name will no longer be
mangled, but of course you can not overload it either.

Good luck!

                     - Thomas

pgsql-bugs by date:

Previous
From: Lonnie Cumberland
Date:
Subject: g++ not working for postgresql extension languages?
Next
From: Martin Willemoes Hansen
Date:
Subject: compile-time-error