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

From: Thomas Lockhart <lockhart(at)alumni(dot)caltech(dot)edu>
To: Lonnie Cumberland <lonnie_cumberland(at)yahoo(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: g++ not working for postgresql extension languages?
Date: 2001-04-15 06:06:18
Message-ID: 3AD93A5A.D40EEFC2@alumni.caltech.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Achim Gottinger 2001-04-15 10:33:08 readline-4.2 problem
Previous Message Lonnie Cumberland 2001-04-15 01:05:00 g++ not working for postgresql extension languages?