Обсуждение: Problem running C function
I'm trying to compile and run my first C function on server side. I considered this simple example from the programmer's guide: #include "postgres.h" #include "fmgr.h" PG_FUNCTION_INFO_V1(add_one); Datum add_one(PG_FUNCTION_ARGS) { int32 arg = PG_GETARG_INT32(0); PG_RETURN_INT32(arg + 1); } I compiled the file libtest.c containing this code and generated libtest.so on a Linux machine by the following commands: cc -fpic -c libtest.c cc -shared -o libtest.so libtest.o Then I registered the function add_one like said in the programmer's guide: CREATE FUNCTION add_one(int4) RETURNS int4 AS .../libtest.so LANGUAGE c WITH (isStrict); Now, when executing SELECT add_one(10); I get the following message: ERROR: Load of file .../libtest.so failed: undefined symbol: PG_GETARG_INT32 Can somebody help me? Thanks. Luca.
"Luca Carrettin" <lucacarrettin@sogeasoft.com> writes: > I get the following message: > ERROR: Load of file .../libtest.so failed: undefined symbol: PG_GETARG_INT32 It looks like the compiler has taken PG_GETARG_INT32 for a function name instead of a macro. This seems odd though, since you included fmgr.h which is where the macro definition is. Perhaps the compiler is finding some obsolete version of fmgr.h? The lack of any -I switches in your cc invocation makes me wonder where it's finding fmgr.h ... Personally I always include "-Wall" in cc invocations, since I don't care for gcc's default willingness to accept unknown names as calls to implicitly declared functions. regards, tom lane