Обсуждение: ecpg and embedded SQL

Поиск
Список
Период
Сортировка

ecpg and embedded SQL

От
rhayhow
Дата:
Hi,

    I am trying to compile a simple program with embedded SQL and have had
a number of problems. My goal is to get a small, simple program that
will connect to and communicate with our database before moving on to a
larger project. I am using Postgres 6.3.2 on a Solaris 2.6 machine. I am
new to Postgres and embedded SQL, so go easy on me.
     I have read the documentation and have searched through both
mailing-list archives, and both were helpful. Unfortunately they have
not been enough to let me finish this project. I am trying to compile
Thomas Good's sample code from http://www.panix.com/~ugd/recipe.html. I
cleared out the Perl code to simplify things. Anyway, when I try to
compile using...

    #!/bin/sh
     tput clear
     echo -ne "Enter name of code file [ omit .pgc ]: "
     read file
     ecpg -o $file.c $file.pgc
     PGBASE="/usr/local/postgresql"
     gcc -g -I ${PGBASE}/include -I ${PGBASE}/libpq -o $file $file.c -L
${PGBASE}/lib
         -lecpg -lpq

I get the following errors...

/usr/local/postgresql/lib/libpq.a(fe-connect.o): In function
`connectDB':
fe-connect.o(.text+0xf6c): undefined reference to `gethostbyname'
fe-connect.o(.text+0x10e0): undefined reference to `socket'
fe-connect.o(.text+0x116c): undefined reference to `connect'
fe-connect.o(.text+0x1218): undefined reference to `getprotobyname'
fe-connect.o(.text+0x127c): undefined reference to `setsockopt'
fe-connect.o(.text+0x12e0): undefined reference to `getsockname'

I have looked at fe-connect.o and it '#includes' two header files,
'socket.h' and 'netdb.h', that contain all of these functions. The files
'socket.h' and 'netdb.h' appear to be fine, so I don't understand what
the problem is. Is there a problem with the linking of libpq.a? Any help
would be greatly appreciated. Thanks.

Reid Hayhow
NBIF
New Mexico State University

Re: [INTERFACES] ecpg and embedded SQL

От
Tom Lane
Дата:
rhayhow <rhayhow@cs.nmsu.edu> writes:
> I get the following errors...
> /usr/local/postgresql/lib/libpq.a(fe-connect.o): In function `connectDB':
> fe-connect.o(.text+0xf6c): undefined reference to `gethostbyname'
> fe-connect.o(.text+0x10e0): undefined reference to `socket'
> fe-connect.o(.text+0x116c): undefined reference to `connect'
> fe-connect.o(.text+0x1218): undefined reference to `getprotobyname'
> fe-connect.o(.text+0x127c): undefined reference to `setsockopt'
> fe-connect.o(.text+0x12e0): undefined reference to `getsockname'

On some systems, these network-related functions are not in the regular
C library, but in other libraries.  Likely you need to add "-lsocket"
or something like that to the link command.

The Postgres configure script presumably got it right, if you were able
to install a working psql.  Try looking at what the makefile for psql
is doing.

            regards, tom lane

Re: [INTERFACES] ecpg and embedded SQL

От
rhayhow
Дата:
Eric and Tom,

    Thanks a ton, adding '-lsocket' to the end of the ddb.compile did the
trick!

Reid Hayhow

---------------------------------------------------------
Eric Marsden wrote:
-snip-
> You probably need to link with the Solaris networking library
> (something like -lsocket or -lnsl, see your system's manuals).
>
> --
> Eric Marsden


Tom Lane wrote:
-snip-
> On some systems, these network-related functions are not in the regular
> C library, but in other libraries.  Likely you need to add "-lsocket"
> or something like that to the link command.
-snip-
>                         regards, tom lane