Running PostgreSQL client in C from Cygwin

I am trying to create a very simple PostgreSQL client in C over Cygwin.

Here is what I have done so far:

  • I downloaded PostgreSQL version 9.1.2 source code (to match the same version as on my server)
  • I 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
  • Libraries are in:
    • /cygdrive/c/workspace/src/postgresql-9.1.2/src/interfaces/libpq

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 

Compilation and linking were performed 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 did not understand how to fix this. Any pointers would be greatly appreciated. Oh, one more thing, I found the folder where cygpq.dll was sitting 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 
+4
source share
1 answer

Typically, on unix / linux systems, after making the source, make make is done, which copies the headers to standard locations, such as / usr / local / include and / usr / local / lib. You may need to do this on cygwin to get the DLL in the search path.

Or you can simply find the DLL yourself and put it in the search path or in the same folder as your executable file.

+1
source

Source: https://habr.com/ru/post/1443874/


All Articles