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

Поиск
Список
Период
Сортировка
От Thomas Lockhart
Тема Re: g++ not working for postgresql extension languages?
Дата
Msg-id 3AD93A5A.D40EEFC2@alumni.caltech.edu
обсуждение исходный текст
Ответ на g++ not working for postgresql extension languages?  (Lonnie Cumberland <lonnie_cumberland@yahoo.com>)
Список 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 по дате отправления:

Предыдущее
От: Lonnie Cumberland
Дата:
Сообщение: g++ not working for postgresql extension languages?
Следующее
От: Martin Willemoes Hansen
Дата:
Сообщение: compile-time-error