Обсуждение: Using shared library's

Поиск
Список
Период
Сортировка

Using shared library's

От
dawizz
Дата:
Dear all,

Recently I started digging into PosgreSQL programming.
I'm using a debian sarge kernel, KDE desktop and more.
G++ is used while compiling.

Next piece of code (funcTest.cpp):

#include "postgres.h"
#include <string.h>
#include "fmgr.h"
#include <iostream>
using namespace std;

// postgres syntax version 1.
PG_FUNCTION_INFO_V1(runTest);

Datum runTest(PG_FUNCTION_ARGS) {
    // do something
    int a;
    a = 0;
    PG_RETURN_INT32(a);
}

I compiled into a so file, on the prompt I used:

>> $     g++ -c -fPIC -isystem /usr/include/postgresql/server funcTest.cpp
>> $     g++ -shared -o funcTest.so funcTest.o

Then with the SQL syntax:

CREATE FUNCTION test() RETURNS integer
AS '/lib/funcTest.so', 'runTest'
LANGUAGE C STRICT;

and I get the error message:

ERROR: Could not find function 'runTest'  in file '/lib/funcTest.so'

As far as I can tell the library should be OK? I used commands like file, nm
and readelf..... But then again....

Does anyone has a good sugestion? Adn how about the fact that type Datum is
used?

With kind regards, Willem Greveling.

Re: Using shared library's

От
Tom Lane
Дата:
dawizz <wwwillem@zonnet.nl> writes:
> and I get the error message:

> ERROR: Could not find function 'runTest'  in file '/lib/funcTest.so'

> As far as I can tell the library should be OK?

No, because you've neglected to prevent C++ name mangling of the
function name.  You need to declare it with "C" linkage.

More generally, the backend is a C engine not a C++ engine, and
you're likely to come to serious grief if you insist on trying to
use C++ libraries (like iostream) in a dynamic library.  I think
you'd be a lot better off to use gcc not g++ ...

            regards, tom lane