PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old May 1st, 2008, 05:20 PM
subordin8 subordin8 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Posts: 6 subordin8 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 7 m 23 sec
Reputation Power: 0
User Defined C Function

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:

Code:
#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:
Code:
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

Code:
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:

Code:
C:\PostgreSQL\8.3\include
C:\PostgreSQL\8.3\include\server
C:\PostgreSQL\8.3\include\server\port\win32"

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

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

-Subordin8

Reply With Quote
  #2  
Old May 2nd, 2008, 02:01 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,687 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 5 Days 17 h 59 m 31 sec
Reputation Power: 259
While I'd really love to see a writeup of your experiences posted here I can't help on this you'd better post to the project lists like pgsql-ports or pgsql-hackers

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > User Defined C Function


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway