"undefined reference" error when compiling extension functions

Поиск
Список
Период
Сортировка
От Mark Miller
Тема "undefined reference" error when compiling extension functions
Дата
Msg-id 20050425203935.86E1B54A46@svr1.postgresql.org
обсуждение исходный текст
Ответы Re: "undefined reference" error when compiling  (Andrew Dunstan <andrew@dunslane.net>)
Список pgsql-hackers-win32

I am trying to figure out how to write extension functions and I am getting “undefined reference” errors when I compile on the lines which call “malloc” and “pfree”. How can I get the compiler to see the functions so I can compile successfully?

 

I installed PostgreSQL on XP Pro using the windows installer, then I installed the includes (which are not part of the windows install) by running the following commands:

 

configure --without-zlib --includedir=/c/progra~1/postgresql/8.0/include --with-includes=/c/progra~1/postgresql/8.0/include/port/win32/*

make -C src/include install

 

 

Here’s the output from make when I try to compile:

 

$ make makefile filesize.dll

make: Nothing to be done for `makefile'.

gcc -g -I c:/Progra~1/PostgreSQL/8.0/include -I c:/Progra~1/PostgreSQL/8.0/include/server -I c:/Progra~1/PostgreSQL/8.0/include/server/port/win32 -I c:/Progra~1/PostgreSQL/8.0/lib -fpic -c filesize.c

cc1.exe: warning: -fpic ignored for target (all code is position independent)

gcc -g -I c:/Progra~1/PostgreSQL/8.0/include -I c:/Progra~1/PostgreSQL/8.0/include/server -I c:/Progra~1/PostgreSQL/8.0/include/server/port/win32 -I c:/Progra~1/PostgreSQL/8.0/lib -shared -o filesize.dll filesize.o

filesize.o(.text+0x1a): In function `filesize':

C:/msys/1.0/home/mark/dev/filesize.c:9: undefined reference to `pg_detoast_datum'

filesize.o(.text+0x3d):C:/msys/1.0/home/mark/dev/filesize.c:11: undefined reference to `_imp__CurrentMemoryContext'

filesize.o(.text+0x44):C:/msys/1.0/home/mark/dev/filesize.c:11: undefined reference to `MemoryContextAlloc'

filesize.o(.text+0x9b):C:/msys/1.0/home/mark/dev/filesize.c:19: undefined reference to `pfree'

filesize.o(.text+0xb1):C:/msys/1.0/home/mark/dev/filesize.c:25: undefined reference to `pfree'

make: *** [filesize.dll] Error 1

 

 

Here’s the source I’m trying to compile (taken from PostgreSQL ch 6 by Douglas and Douglas):

 

#include "postgres.h"

#include "fmgr.h"

#include <sys/stat.h>

 

PG_FUNCTION_INFO_V1(filesize);

 

Datum filesize(PG_FUNCTION_ARGS)

{

            text * fileNameText = PG_GETARG_TEXT_P(0);

            size_t fileNameLen = VARSIZE( fileNameText ) - VARHDRSZ;

            char * fileName = (char *)palloc( fileNameLen + 1 );

            struct stat statBuf;

 

            memcpy( fileName, VARDATA( fileNameText), fileNameLen );

            fileName[fileNameLen] = '\0';

 

            if( stat(fileName, &statBuf) == 0 && S_ISREG(statBuf.st_mode) )

            {

                        pfree( fileName );

 

                        PG_RETURN_INT32((int32)statBuf.st_size);

            }

            else

            {

                        pfree( fileName );

 

                        PG_RETURN_NULL();

            }

}

 

Here’s the makefile, from the same example but modified to include the needed include directories and to output “.dll” file instead of “.so”.

 

# File name: makefile

SERVER_INCLUDES += -I $(shell pg_config --includedir)

SERVER_INCLUDES += -I $(shell pg_config --includedir-server)

SERVER_INCLUDES += -I $(shell pg_config --includedir-server)/port/win32

SERVER_INCLUDES += -I $(shell pg_config --libdir)

 

CFLAGS += -g $(SERVER_INCLUDES)

 

.SUFFIXES:      .dll

 

.c.dll:

            $(CC) $(CFLAGS) -fpic -c $<

            $(CC) $(CFLAGS) -shared -o $@ $(basename $<).o

 

В списке pgsql-hackers-win32 по дате отправления:

Предыдущее
От: John DeSoi
Дата:
Сообщение: Re: Custom Install
Следующее
От: Andrew Dunstan
Дата:
Сообщение: Re: "undefined reference" error when compiling