Re: "undefined reference" error when compiling extension functions

From: "Mark Miller" <mark(at)maxpreps(dot)com>
To: <pgsql-hackers-win32(at)postgresql(dot)org>
Subject: Re: "undefined reference" error when compiling extension functions
Date: 2005-04-25 22:23:03
Message-ID: 20050425222555.DBB55534BA@svr1.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers-win32

You're right, I could just install it there. That's the easiest way around
it. But I WOULD like to know why it's mapping to the wrong directory and how
to work around it. It would be better if I could install it where ever I
like. I'm doing this all as a learning experince. Since I have no experience
with any of these technologies (C, postgresql, gcc, makefiles), I just want
to figure out how to do it right.

Thanks,
Mark

-----Original Message-----
From: Andrew Dunstan [mailto:andrew(at)dunslane(dot)net]
Sent: Monday, April 25, 2005 3:15 PM
To: mark(at)maxpreps(dot)com
Subject: Re: [pgsql-hackers-win32] "undefined reference" error when
compiling extension functions

Install instead to

C:\MSYS\1.0\local\pgsql - under MSys that will map to /usr/local/pgsql

Personally, if I were building extensions I would have built/installed pg
from scratch, rather than using the installer.

cheers

andrew

Mark Miller wrote:

>Thanks, that simplifies things.
>
>But I ran into the following problem:
>
>$ make
>dlltool --export-all --output-def filesize.def filesize.o
>dllwrap -o filesize.dll --def filesize.def filesize.o
>c:/Progra~1/PostgreSQL/8.0/lib/pgxs/src/makefiles/../../src/utils/dllinit.o
>-L/usr/local/pgsql/bin -lpostgres
>c:\MinGW\bin\..\lib\gcc-lib\mingw32\3.2.3\..\..\..\..\mingw32\bin\ld.exe:
>cannot find -lpostgres
>c:\MinGW\bin\dllwrap.exe: c:\MinGW\bin\gcc exited with status 1
>make: *** [filesize.dll] Error 1
>
>
>Here's the makefile (located in /home/usr/dev (windows path is:
>C:\MSYS\1.0\home\mark\dev) ***:
>
>
>MODULES = filesize
>
>PGXS := $(shell pg_config --pgxs)
>include $(PGXS)
>
>*** ( postgresql is installed in C:\Progra~1\postgresql\8.0\)
>
>It looks like "-L/usr/local/pgsql/bin -lpostgres" is looking in the wrong
>directory. I reinstalled making sure I used the --prefix parameter for
>configure, but it's still looking in the wrong place. How do I point it to
>the right "bin" directory?.
>
>Again, I did a windows install followed by using MinGW and MSYS to install
>the headers needed for development. (The reason for doing separate installs
>was so I could install PostgreSQL as a service and make sure the proper
>accounts were set up).
>
>Thanks again for your help,
>Mark
>
>
>-----Original Message-----
>From: Andrew Dunstan [mailto:andrew(at)dunslane(dot)net]
>Sent: Monday, April 25, 2005 2:05 PM
>To: mark(at)maxpreps(dot)com
>Cc: pgsql-hackers-win32(at)postgresql(dot)org
>Subject: Re: [pgsql-hackers-win32] "undefined reference" error when
>compiling extension functions
>
>
>You might find using the pgxs setup, new in 8.0, useful. See
>http://www.postgresql.org/docs/current/static/xfunc-c.html#XFUNC-C-PGXS
>
>cheers
>
>andrew
>
>Mark Miller wrote:
>
>
>
>>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
>>
>>
>>
>
>
>

Responses

Browse pgsql-hackers-win32 by date

  From Date Subject
Next Message Andrew Dunstan 2005-04-25 22:46:59 Re: "undefined reference" error when compiling
Previous Message Andrew Dunstan 2005-04-25 21:04:49 Re: "undefined reference" error when compiling