Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

running PostgreSQL client in C from Cygwin

I'm trying to build a very simple PostgreSQL client in C over Cygwin.

Here's what I've done so far:

  • I've downloaded the PostgreSQL source code version 9.1.2 (to match the same version that is running on my server)
  • I've configured and compiled the source code from Cygwin. The compilation seemed to go smoothly.
  • From what I can tell, the header files are in:
    • /cygdrive/c/workspace/src/postgresql-9.1.2/src/interfaces/libpq, and
    • /cygdrive/c/workspace/src/postgresql-9.1.2/src/include
  • The libraries are in:
    • /cygdrive/c/workspace/src/postgresql-9.1.2/src/interfaces/libpq

From here, I compiled and linked the client program using the makefile below:

testlibpq: testlibpq.c
    gcc -o testlibpq -I /cygdrive/c/workspace/src/postgresql-9.1.2/src/interfaces/libpq -I /cygdrive/c/workspace/src/postgresql-9.1.2/src/include -L /cygdrive/c/workspace/src/postgresql-9.1.2/src/interfaces/libpq testlibpq.c -Bstatic -lpq

The compilation and the linking succeeded without errors or warnings.

However, when I try to run the program, I get the following error:

$ ./testlibpq
/cygdrive/c/Users/dleclair/Dropbox/denis/src/testlibpq/testlibpq.exe: error while loading shared libraries: cygpq.dll: cannot open shared object file: No such file or directory

I haven't figured out how to fix this. Any pointers would be greatly appreciated. Oh, one more thing, I found the folder that cygpq.dll was sitting in and set my LD_LIBRARY_PATH to point to it but it still gave me the same result.

dleclair@dleclair-win7l ~/Dropbox/denis/src/testlibpq
$ ls /cygdrive/c/workspace/src/postgresql-9.1.2/src/interfaces/libpq
bcc32.mak      encnames.o    fe-connect.o  fe-misc.o       fe-protocol3.o   ip.o           libpq-events.c  md5.c                   pgstrcasecmp.c  pqsignal.c       thread.o
blibpqdll.def  exports.txt   fe-exec.c     fe-print.c      fe-secure.c      libpq.a        libpq-events.h  md5.o                   pgstrcasecmp.o  pqsignal.h       wchar.c
chklocale.c    fe-auth.c     fe-exec.o     fe-print.o      fe-secure.o      libpq.rc.in    libpq-events.o  nls.mk                  po              pqsignal.o       wchar.o
chklocale.o    fe-auth.h     fe-lobj.c     fe-protocol2.c  inet_net_ntop.c  libpqddll.def  libpq-fe.h      noblock.c               pqexpbuffer.c   pthread-win32.c  win32.c
cygpq.dll      fe-auth.o     fe-lobj.o     fe-protocol2.o  inet_net_ntop.o  libpq-dist.rc  libpq-int.h     noblock.o               pqexpbuffer.h   README           win32.h
encnames.c     fe-connect.c  fe-misc.c     fe-protocol3.c  ip.c             libpqdll.def   Makefile        pg_service.conf.sample  pqexpbuffer.o   thread.c         win32.mak

dleclair@dleclair-win7l ~/Dropbox/denis/src/testlibpq
$ echo $LD_LIBRARY_PATH
/cygdrive/c/workspace/src/postgresql-9.1.2/src/interfaces/libpq

dleclair@dleclair-win7l ~/Dropbox/denis/src/testlibpq
like image 770
Denis Avatar asked Nov 13 '22 18:11

Denis


1 Answers

Normally on unix/linux systems after building the source a make install is done which copies the headers to standard locations like /usr/local/include and /usr/local/lib. You may have to do that on cygwin to to get the DLL in the search path.

Or you can just locate the DLL yourself and put it on the search path or in the same folder as your executable.

like image 101
Eelke Avatar answered Dec 21 '22 16:12

Eelke