Re: Compiling a user C function in 7.2.1

From: John Gunther <inbox(at)bucksvsbytes(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Compiling a user C function in 7.2.1
Date: 2002-07-28 12:29:09
Message-ID: 3D43E395.603@bucksvsbytes.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Tom Lane wrote:

>(a) you didn't run configure, which creates the files you are missing.
>
>
Thanks, Tom. Your reply caused me to learn a lot about building
PostgreSQL from source.

Now I'm much further along: I have created a dynamic library
(bvbpglib.so) containing one PostgreSQL C function (bvbpgsortword). This
function calls a "regular" (non-PostgreSQL) C function (bvbmakesortstring).

My current problem is that my psql statement:
CREATE FUNCTION bvbpgsortword(TEXT) RETURNS TEXT AS
'/usr/include/bvbpglib' LANGUAGE C WITH (ISSTRICT);
fails with "undefined symbol: bvbmakesortstring"

This is probably the result of some fundamental deficit in my
understanding of C writing/compiling/linking, but what puzzles me is
that bvbmakesortstring is called successfully from another C program I
wrote. Only in psql does it come back undefined.

Thanks.

John Gunther

For anyone is interested in enlightening me, relevant source follows:

SOURCE FOR bvbpglib.c (used to create bvbpglib.so, contains PostgreSQL
function bvbpgsortword):
#include "postgres.h"
#include "fmgr.h"
#include <string.h>
#include "bvblib.h"
Datum bvbpgsortword(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(bvbpgsortword);
Datum bvbpgsortword(PG_FUNCTION_ARGS){
//declarations
char *bvbmakesortstring(const char *input, const int bitmodes,
const unsigned short int minlength, const char *keeplist, const char
*outdelim, const char *stoplist);
text *instr = PG_GETARG_TEXT_P(0);
text *outstr;
unsigned int length;
char *target;
//code
target=VARDATA(outstr);
target = bvbmakesortstring(VARDATA(instr),1,0,"","}","");
length=strlen(target-1);
target[length]=0;
VARATT_SIZEP(outstr) = length + VARHDRSZ;
PG_RETURN_TEXT_P(outstr);
}

SOURCE FOR test.c (this successfully calls bvbmakesortstring):
#include <stdio.h>
#include "bvblib.h"
int /*function*/ main(){

printf("out=%s\n",bvbmakesortstring("test-mctöst'tëst",0,0,",","=","A"));
return 0;
}

PARTIAL SOURCE FOR bvblib.c (this library contains bvbmakesortstring):
#include <string.h>
#include "bvblib.h"
char bvbstr[65535];
char *bvbmakesortstring(
const char *instr,
const int bitmodes,
const unsigned short int minlength,
const char *keeplist,
const char *outdelim,
const char *stoplist
)
{<code>...
return bvbstr;//return the sort-ready string
}

SOURCE FOR bvblib.h:
#ifndef BVBLIB_H /* has this been included */
#define BVBLIB_H /* if not say its been done once */
char bvbstr[65535];
char *bvbmakesortstring(
const char *instr, //string to be
processed
const int bitmodes,
const unsigned short int minlength, //words shorter than this
are ignored
const char *keeplist, //chars to
be kept in output words
const char *outdelim, //char
string to use as word delimiter
const char *stoplist
//space-separated words to be ignored
);
#endif /* end the #ifndef construct */

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message John Gunther 2002-07-28 12:36:39 Re: Compiling a user C function in 7.2.1
Previous Message tom wa 2002-07-27 20:47:32 functions