Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql General > User Defined C ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 15448 of 15987
Post > Topic >>

User Defined C Function with minGW

by n8thatcher@[EMAIL PROTECTED] ("Nathan Thatcher") May 2, 2008 at 09:34 AM

I have been creating some user defined C functions using minGW and
postgreSQL 8.3. Everything works great when I use integers,
timestamps, points, etc. I have compiled, linked, created, and tested
multiple function and aggregates.

The problem occurs when I have a text parameter and need to use
PG_GETARG_TEXT_P(n). The code compiles just fine but linking fails.
Here is an example:

#include "postgres.h"
#include "fmgr.h"

PG_MODULE_MAGIC;

PG_FUNCTION_INFO_V1(function);

Datum
function(PG_FUNCTION_ARGS)
{
	text *t = PG_GETARG_TEXT_P(1);
	int32 i = PG_GETARG_INT32(0);
	PG_RETURN_INT32(i+1);
}

The error:
X)function_name.o:function_name.c: undefined reference to
`pg_detoast_datum'
If I comment out the text *t line then it compiles, links, and
executes just fine.

The problem (I am assuming it is the same problem) also manifests
itself when I make a call to palloc. I get 2 errors

X) finalagent.o:finalagent.c: undefined reference to
`_imp__CurrentMemoryContext'
X) finalagent.o:finalagent.c: undefined reference to `MemoryContextAlloc'

Some people have said that this error should just be ignored and it
will sort itself out at run-time. That sounds swell but how do I get
my linker to ignore these errors?

Other people have said that pg_detoast_datum is a backend function and
shouldn't be referenced at all, but it is right there in fmgr.h which
is obviously required for creating functions under the V1 calling
convention.

For reference, I am on Windows XP SP2. I installed postgreSQL 8.3 from
the msi and selected to include the Development components (Include
Files, Library Files, Tools and utilities). The compiler is including
the following directories:

C:\PostgreSQL\8.3\include
C:\PostgreSQL\8.3\include\server
C:\PostgreSQL\8.3\include\server\****t\win32"

I added both C:\PostgreSQL\8.3\lib and C:\PostgreSQL\8.3\bin to my
linker hoping that maybe it would work. It didn't.

Any information, insight, tips, or criticism would be welcomed and
appreciated.

-Subordin8

-- 
Sent via pgsql-general mailing list (pgsql-general@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
 




 2 Posts in Topic:
User Defined C Function with minGW
n8thatcher@[EMAIL PROTECT  2008-05-02 09:34:31 
Re: User Defined C Function with minGW
kleptog@[EMAIL PROTECTED]  2008-05-04 13:16:55 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan13V112 Sun Jul 6 18:30:41 CDT 2008.