Thread: Load C++ for functions?
I'm trying to link up a C++ project with postgres functions, the following code compiles (as C++): extern "C" { #include <postgres.h> #include <fmgr.h> #ifdef PG_MODULE_MAGIC PG_MODULE_MAGIC; #endif }; extern "C" { PG_FUNCTION_INFO_V1(pg_xversion); }; extern "C" Datum pg_xversion(PG_FUNCTION_ARGS) { PG_RETURN_NULL(); } But the CREATE FUNCTION gives the error: ERROR: could not load library "/storage/Scripts/pgx/pgx.so": /storage/Scripts/pgx/pgx.so: undefined symbol: __gxx_personality_v0 Postgres is no doubt trying to load a C++ linked library as C - is there a way to fix this?
Hey Elliot,
See http://www.postgresql.org/docs/9.0/static/extend-cpp.html
Probably compiling with -fno-exceptions solve you problem.
--
// Dmitriy.
See http://www.postgresql.org/docs/9.0/static/extend-cpp.html
Probably compiling with -fno-exceptions solve you problem.
2010/12/24 Elliot Chance <elliotchance@gmail.com>
I'm trying to link up a C++ project with postgres functions, the following code compiles (as C++):
extern "C" {
#include <postgres.h>
#include <fmgr.h>
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
};
extern "C" {
PG_FUNCTION_INFO_V1(pg_xversion);
};
extern "C" Datum pg_xversion(PG_FUNCTION_ARGS)
{
PG_RETURN_NULL();
}
But the CREATE FUNCTION gives the error:
ERROR: could not load library "/storage/Scripts/pgx/pgx.so": /storage/Scripts/pgx/pgx.so: undefined symbol: __gxx_personality_v0
Postgres is no doubt trying to load a C++ linked library as C - is there a way to fix this?
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
--
// Dmitriy.
Cheers! It works.
On 24/12/2010, at 11:13 PM, Dmitriy Igrishin wrote:
Hey Elliot,
See http://www.postgresql.org/docs/9.0/static/extend-cpp.html
Probably compiling with -fno-exceptions solve you problem.2010/12/24 Elliot Chance <elliotchance@gmail.com>I'm trying to link up a C++ project with postgres functions, the following code compiles (as C++):
extern "C" {
#include <postgres.h>
#include <fmgr.h>
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
};
extern "C" {
PG_FUNCTION_INFO_V1(pg_xversion);
};
extern "C" Datum pg_xversion(PG_FUNCTION_ARGS)
{
PG_RETURN_NULL();
}
But the CREATE FUNCTION gives the error:
ERROR: could not load library "/storage/Scripts/pgx/pgx.so": /storage/Scripts/pgx/pgx.so: undefined symbol: __gxx_personality_v0
Postgres is no doubt trying to load a C++ linked library as C - is there a way to fix this?
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
--
// Dmitriy.
On 12/24/2010 10:29 PM, Elliot Chance wrote: > But the CREATE FUNCTION gives the error: > ERROR: could not load library "/storage/Scripts/pgx/pgx.so": /storage/Scripts/pgx/pgx.so: undefined symbol: __gxx_personality_v0 How'd you build the C++ code? What was your compile command line? Does 'ldd pgx.so' list libstdc++ as a dependency? Are you for some reason compiling with -fno-exceptions? Is every single one of your C++ functions wrapped with an unconditional try/catch that converts any exceptions to error return codes/Pg elog() calls? I've written Pg extension modules, but I've always done so by compiling the component containing PG_MODULE_MAGIC, PG_FUNCTION_INFO_V1, PG_FUNCTION_ARGS, etc as regular C, and having it call "extern C" functions in the C++ files linked into the shared object. I don't *think* this should make any difference, but I'm far from a C/C++ expert. > Postgres is no doubt trying to load a C++ linked library as C - is there a way to fix this? AFAIK, dlopen() doesn't care if a library is C, C++, or BlueLanguage, so long as it provides standard ELF symbols and a C-compatible entry point. -- Craig Ringer
On 12/24/2010 11:16 PM, Elliot Chance wrote: > Cheers! It works. Beware - that's really unsafe if you're calling C++ libraries that may throw exceptions. -- Craig Ringer