could not load library; undefined symbol: itoa

From: bence(at)net(dot)info(dot)hu
To: pgeu-general(at)postgresql(dot)org
Subject: could not load library; undefined symbol: itoa
Date: 2009-04-21 09:08:29
Message-ID: 52673ce24d84a1b32bf0fefeb316fc6e.squirrel@mail.net.info.hu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgeu-general

Hi!

I' have tried to add a C language function called 'djb_hash' to my databse.
It accepts a 32 chars length text as input, and returns a ten chars length
numeric string.
It implements the 'djb_hash' string hash algorithm, wich unfortunetly returns
unsigned int type, so a I had to write it as a C language function. So I
had to convert the return value to text. I used to compile it with MinGW
and used it on Windows, but now I'd like to use on Linux (Ubuntu 9.04,
PostgreSQL 8.3).
When I was trying to compile, I ran into numerous errors that concerned
type definitions in the headrs (postgres.h, fmgr.h, c.h). The point is
I have changed the 'varlena' definition in the 'c.h' (the vl_len_ is now
int) Now I have successfully complied, but I can't add it because it
complains about:

undefined symbol: itoa

Here is the definition of the function:
#include <math.h>
#include <string.h>
#include "/usr/include/postgresql/8.3/server/postgres.h"
#include "/usr/include/postgresql/8.3/server/fmgr.h"

#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif

PG_FUNCTION_INFO_V1(djb_hash);
Datum
djb_hash(PG_FUNCTION_ARGS)
{
char buffer[32];
char output[11];
char* str;
text *szoveg = PG_GETARG_TEXT_P(0);
text *hash_text = (text*) palloc(VARHDRSZ+10);
hash_text->vl_len_ = VARHDRSZ+10;

unsigned int hash = 5381;
unsigned int i = 0;
unsigned int number = 0;

memcpy(buffer,szoveg->vl_dat,32);
str = &buffer[0];

for(i=0; i<32; str++, i++)
{
hash = ((hash << 5) + hash) + (*str);
}

str = &output[0];
number = hash/pow(10,9);

if(number != 0)
{
hash = hash - number*pow(10,9);
(*str) = '0'+ number;
}
else
(*str)='0';

str++;

for(i=8;str;str++,i--)
{
number = 0;
number = hash/pow(10,i);

if (number == 0)
(*str) = '0';

else
{
itoa((int)hash, str, 10);
break;
}
}

memcpy(hash_text->vl_dat,output,10);

PG_RETURN_TEXT_P(hash_text);
}

I probably missed something. So any idea would be helpful.
Thanks in advance.

Responses

Browse pgeu-general by date

  From Date Subject
Next Message Alexey Klyukin 2009-04-21 10:51:30 Re: could not load library; undefined symbol: itoa
Previous Message Andreas 'ads' Scherbaum 2009-02-18 00:24:18 Re: account