Thread: A "linking" Question

A "linking" Question

From
Terry Lee Tucker
Date:
Let me explain:

I have written a "C" function which contains calls to other functions, all of
which work with an API to a mileage database product called PCMiler. These
functions make connections to the PCMiler databae, do error checking on the
origin and destination, get directions, etc. There is only one function
loaded into postgres and it makes calls to everything else. I create a shared
object library containing one object file: pcmiler.o and also containing a
link to the PCMiler SO, libpcmsrv.so. Here is the make file code:

libpcmiler.so: utility/pcmiler.h logpro.h utility/pcmiler.c
    rm libpcmiler* -f
    gcc -Wall -fPIC $(APPINC) -DUNIX -c utility/pcmiler.c
    gcc -shared -W1,-soname,libpcmiler.so.1 $(PCMSRVLIB) -o libpcmiler.so.1.0
pcmiler.o
    ln -s libpcmiler.so.1.0 libpcmiler.so.1
    ln -s libpcmiler.so.1 libpcmiler.so
    psql rnd < sqlfunc/loadCfuncs.sql

The function loads into postgres and everything works flawlessly. Now, we have
an X-Windows front end to this application which is a transportation app.
Obviously, we need to do lots of mileage lookups. There are times when I need
to make call to some of the functions residing in pcmiler.c bypassing the
call to the postgres function. I thought I could simply link my pcmiler
shared library with my app binary, but I get errors when I do that. Here they
are:
 pcmiler.o(.text+0x8d): In function `PCMilerConnect':
: undefined reference to `elog'
pcmiler.o(.text+0x12a): In function `PCMGetMiles':
: undefined reference to `elog'
pcmiler.o(.text+0x166): In function `PCMGetMiles':
: undefined reference to `elog'
pcmiler.o(.text+0x3c3): In function `psql_pcmgetmiles':
: undefined reference to `pg_detoast_datum'
pcmiler.o(.text+0x3d7): In function `psql_pcmgetmiles':
: undefined reference to `pg_detoast_datum'
pcmiler.o(.text+0x3ff): In function `psql_pcmgetmiles':
: undefined reference to `CurrentMemoryContext'
pcmiler.o(.text+0x406): In function `psql_pcmgetmiles':
: undefined reference to `MemoryContextAlloc'
pcmiler.o(.text+0x423): In function `psql_pcmgetmiles':
: undefined reference to `CurrentMemoryContext'
pcmiler.o(.text+0x42a): In function `psql_pcmgetmiles':
: undefined reference to `MemoryContextAlloc'
pcmiler.o(.text+0x48a): In function `psql_pcmgetmiles':
: undefined reference to `elog'
pcmiler.o(.text+0x4dc): In function `psql_pcmgetmiles':
: undefined reference to `pfree'
pcmiler.o(.text+0x4ea): In function `psql_pcmgetmiles':
: undefined reference to `pfree'
pcmiler.o(.text+0x51f): In function `psql_pcmgetmiles':
: undefined reference to `Float8GetDatum'
collect2: ld returned 1 exit status
make: *** [logpro] Error 1

All the complaints are regarding pgsql server functions. Obviously, I need to
link with some sort of library, but I don't know which one. I'm already
linking with libpq and I tried libepcg but that didn't work. I'm not very
knowledgeable regarding some of these things so please excuse my ingorance.
Can somebody give me a clue as to the error of my ways?

Thanks...

--
Quote: 6
"[G]un control often serves as a gateway to tyranny. Tyrants from Hitler
 to Mao to Stalin have sought to disarm their own citizens, for the simple
 reason that unarmed people are easier to control. Our Founders, having
 just expelled the British army, knew that the right to bear arms serves
 as the guardian of every other right. This is the principle so often
 ignored by both sides in the gun control debate. Only armed citizens can
 resist tyrannical government."

 --Ron Paul

 Work: 1-336-372-6812
 Cell: 1-336-363-4719
email: terry@esc1.com

Re: A "linking" Question

From
Martijn van Oosterhout
Date:
On Thu, Jun 03, 2004 at 09:08:40AM -0400, Terry Lee Tucker wrote:
> Let me explain:
>
> I have written a "C" function which contains calls to other functions, all of
> which work with an API to a mileage database product called PCMiler. These
> functions make connections to the PCMiler databae, do error checking on the
> origin and destination, get directions, etc. There is only one function
> loaded into postgres and it makes calls to everything else. I create a shared
> object library containing one object file: pcmiler.o and also containing a
> link to the PCMiler SO, libpcmsrv.so. Here is the make file code:

<snip>

> All the complaints are regarding pgsql server functions. Obviously, I need to
> link with some sort of library, but I don't know which one. I'm already
> linking with libpq and I tried libepcg but that didn't work. I'm not very
> knowledgeable regarding some of these things so please excuse my ingorance.
> Can somebody give me a clue as to the error of my ways?

There is no library with those functions. They exist within the server
binary itself and are exported to dynamically linked modules that are
loaded in.

I think you need to split your library in two, one part which depends
on being loaded into postgresql and the part that can be used standalone.

--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Attachment

Re: A "linking" Question

From
Terry Lee Tucker
Date:
Ah, that's the information I needed. I already have a "split" version, I just
wanted to know if it was possible to it the other way. You've been very
helpful.

Thanks...

On Thursday 03 June 2004 09:50 am, Martijn van Oosterhout saith:
> On Thu, Jun 03, 2004 at 09:08:40AM -0400, Terry Lee Tucker wrote:
> > Let me explain:
> >
> > I have written a "C" function which contains calls to other functions,
> > all of which work with an API to a mileage database product called
> > PCMiler. These functions make connections to the PCMiler databae, do
> > error checking on the origin and destination, get directions, etc. There
> > is only one function loaded into postgres and it makes calls to
> > everything else. I create a shared object library containing one object
> > file: pcmiler.o and also containing a link to the PCMiler SO,
> > libpcmsrv.so. Here is the make file code:
>
> <snip>
>
> > All the complaints are regarding pgsql server functions. Obviously, I
> > need to link with some sort of library, but I don't know which one. I'm
> > already linking with libpq and I tried libepcg but that didn't work. I'm
> > not very knowledgeable regarding some of these things so please excuse my
> > ingorance. Can somebody give me a clue as to the error of my ways?
>
> There is no library with those functions. They exist within the server
> binary itself and are exported to dynamically linked modules that are
> loaded in.
>
> I think you need to split your library in two, one part which depends
> on being loaded into postgresql and the part that can be used standalone.

--

 Work: 1-336-372-6812
 Cell: 1-336-363-4719
email: terry@esc1.com