Thread: libpq compile error

libpq compile error

From
Olivier Cherrier
Date:
Hello.

I try to compile the 1.1 example code which is shown at the page
http://postgresql.mirror.easynet.be/users-lounge/docs/7.1/programmer/libpq-e
xample.html.

I run OpenBSD 2.9 (i386) and I installed the 7.1 Postgresql client
interface.

I do this :


bash-2.04$
bash-2.04$
bash-2.04$
bash-2.04$ gcc -v -I/usr/local/include/postgresql/ -o testlibpq testlibpq.c

Reading specs from /usr/lib/gcc-lib/i386-unknown-openbsd2.9/2.95.3/specs
gcc version 2.95.3 20010125 (prerelease)
 /usr/lib/gcc-lib/i386-unknown-openbsd2.9/2.95.3/cpp0 -lang-c -v
-I/usr/local/include/post
gresql/ -D__GNUC__=2 -D__GNUC_MINOR__=95 -D__unix__ -D__i386__ -D__OpenBSD__
-D__unix__ -D
__i386__ -D__OpenBSD__ -Asystem(unix) -Asystem(OpenBSD) -Acpu(i386)
-Amachine(i386) testli
bpq.c /tmp/cctlz476.i
GNU CPP version 2.95.3 20010125 (prerelease) (80386, BSD syntax)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include/postgresql
 /usr/include
End of search list.
The following default directories have been omitted from the search path:
 /usr/include/g++
End of omitted list.
 /usr/lib/gcc-lib/i386-unknown-openbsd2.9/2.95.3/cc1 /tmp/cctlz476.i -quiet
-dumpbase test
libpq.c -version -o /tmp/ccLqy476.s
GNU C version 2.95.3 20010125 (prerelease) (i386-unknown-openbsd2.9)
compiled by GNU C ver
sion 2.95.3 20010125 (prerelease).
 as -o /tmp/ccSis476.o /tmp/ccLqy476.s
 /usr/lib/gcc-lib/i386-unknown-openbsd2.9/2.95.3/collect2 -e start -dc -dp
-o testlibpq /u
sr/lib/crt0.o -L/usr/lib/gcc-lib/i386-unknown-openbsd2.9/2.95.3
/tmp/ccSis476.o -lgcc -lc
-lgcc
/tmp/ccSis476.o: Undefined symbol `_PQfinish' referenced from text segment
/tmp/ccSis476.o: Undefined symbol `_PQsetdbLogin' referenced from text
segment
/tmp/ccSis476.o: Undefined symbol `_PQstatus' referenced from text segment
/tmp/ccSis476.o: Undefined symbol `_PQerrorMessage' referenced from text
segment
/tmp/ccSis476.o: Undefined symbol `_PQexec' referenced from text segment
/tmp/ccSis476.o: Undefined symbol `_PQresultStatus' referenced from text
segment
/tmp/ccSis476.o: Undefined symbol `_PQclear' referenced from text segment
/tmp/ccSis476.o: Undefined symbol `_PQclear' referenced from text segment
/tmp/ccSis476.o: Undefined symbol `_PQexec' referenced from text segment
/tmp/ccSis476.o: Undefined symbol `_PQresultStatus' referenced from text
segment
/tmp/ccSis476.o: Undefined symbol `_PQclear' referenced from text segment
/tmp/ccSis476.o: Undefined symbol `_PQclear' referenced from text segment
/tmp/ccSis476.o: Undefined symbol `_PQexec' referenced from text segment
/tmp/ccSis476.o: Undefined symbol `_PQresultStatus' referenced from text
segment
/tmp/ccSis476.o: Undefined symbol `_PQclear' referenced from text segment
/tmp/ccSis476.o: Undefined symbol `_PQnfields' referenced from text segment
/tmp/ccSis476.o: Undefined symbol `_PQfname' referenced from text segment
/tmp/ccSis476.o: Undefined symbol `_PQntuples' referenced from text segment
/tmp/ccSis476.o: Undefined symbol `_PQgetvalue' referenced from text segment
/tmp/ccSis476.o: Undefined symbol `_PQclear' referenced from text segment
/tmp/ccSis476.o: Undefined symbol `_PQexec' referenced from text segment
/tmp/ccSis476.o: Undefined symbol `_PQclear' referenced from text segment
/tmp/ccSis476.o: Undefined symbol `_PQexec' referenced from text segment
/tmp/ccSis476.o: Undefined symbol `_PQclear' referenced from text segment
/tmp/ccSis476.o: Undefined symbol `_PQfinish' referenced from text segment
collect2: ld returned 1 exit status

Re: libpq compile error

From
zilch@home.se
Date:
> bash-2.04$ gcc -v -I/usr/local/include/postgresql/ -o testlibpq testlibpq.c

Now tell yourself where do you tell the compiler where all the postgresql
code is! The compiler itself wont give you the code for all your postgresql
specific function calls.

try add "-lpq" to the end of the line.

gcc -o testlibpq testlibpq.c -lpq

Daniel Akerud

RE: libpq compile error

From
Olivier Cherrier
Date:
>> bash-2.04$ gcc -v -I/usr/local/include/postgresql/ -o
>testlibpq testlibpq.c
>
>Now tell yourself where do you tell the compiler where all the
>postgresql
>code is! The compiler itself wont give you the code for all
>your postgresql
>specific function calls.
>
>try add "-lpq" to the end of the line.


Unfortunately, It doesn't help:

<<
bash-2.04$ gcc -I/usr/local/include/postgresql/ -o testlibpq testlibpq.c
-lpq
ld: -lpq: no match
collect2: ld returned 1 exit status
bash-2.04$
>>

"man gcc" gives that "-l" is for libraries.

I also tried:

<<
bash-2.04$ gcc -I/usr/local/include/postgresql/
-L/usr/local/include/postgresql/
-o testlibpq testlibpq.c -lpq
>>

But I get the same original error (Undefined symbol).


Thanks for help.

Olivier

>
>gcc -o testlibpq testlibpq.c -lpq
>
>Daniel Akerud
>
>---------------------------(end of
>broadcast)---------------------------
>TIP 2: you can get off all lists at once with the unregister command
>    (send "unregister YourEmailAddressHere" to
>majordomo@postgresql.org)
>

RE: libpq compile error

From
Einar Karttunen
Date:
On Fri, 8 Jun 2001, Olivier Cherrier wrote:
> >> bash-2.04$ gcc -v -I/usr/local/include/postgresql/ -o
> >testlibpq testlibpq.c
> >
> >Now tell yourself where do you tell the compiler where all the
> >postgresql
> >code is! The compiler itself wont give you the code for all
> >your postgresql
> >specific function calls.
> >
> >try add "-lpq" to the end of the line.
>
>
> Unfortunately, It doesn't help:
>
> <<
> bash-2.04$ gcc -I/usr/local/include/postgresql/ -o testlibpq testlibpq.c
> -lpq
> ld: -lpq: no match
> collect2: ld returned 1 exit status
> bash-2.04$
> >>


gcc -o testlibpq testlibpq.c -Iinclude_dir -Llib_dir -lpq

include_dir is the directory containing pgsql header files (*.h).
lib_dir is the directory containing pgsql libraries (eg. libpq.so)

You can locate the libdir by find / -name 'libpq.so*'

- Einar Karttunen




RE: libpq compile error

From
Olivier Cherrier
Date:
>
>
>
>
>gcc -o testlibpq testlibpq.c -Iinclude_dir -Llib_dir -lpq
>
>include_dir is the directory containing pgsql header files (*.h).
>lib_dir is the directory containing pgsql libraries (eg. libpq.so)
>
>You can locate the libdir by find / -name 'libpq.so*'

OK. Now, it works fine!

Thanks a lot for your beautiful help.

Olivier

>
>- Einar Karttunen
>
>
>