gpt4 book ai didi

postgresql - 从 Cygwin 在 C 中运行 PostgreSQL 客户端

转载 作者:行者123 更新时间:2023-11-29 11:37:09 25 4
gpt4 key购买 nike

我正尝试在 Cygwin 上用 C 构建一个非常简单的 PostgreSQL 客户端。

这是我到目前为止所做的:

  • 我已经下载了 PostgreSQL 源代码版本 9.1.2(以匹配我服务器上运行的相同版本)
  • 我已经配置并编译了来自 Cygwin 的源代码。编译似乎进行得很顺利。
  • 据我所知,头文件位于:
    • /cygdrive/c/workspace/src/postgresql-9.1.2/src/interfaces/libpq, 和
    • /cygdrive/c/workspace/src/postgresql-9.1.2/src/include
  • 图书馆位于:
    • /cygdrive/c/workspace/src/postgresql-9.1.2/src/interfaces/libpq

从这里开始,我使用下面的 makefile 编译并链接了客户端程序:

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

编译和链接成功,没有错误或警告。

但是,当我尝试运行该程序时,出现以下错误:

$ ./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

我还没想好怎么解决这个问题。任何指针将不胜感激。哦,还有一件事,我找到了 cygpq.dll 所在的文件夹并将我的 LD_LIBRARY_PATH 设置为指向它,但它仍然给了我相同的结果。

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

最佳答案

通常在 unix/linux 系统上构建源代码后会执行 make install,将 header 复制到标准位置,如/usr/local/include 和/usr/local/lib。您可能必须在 cygwin 上执行此操作才能在搜索路径中获取 DLL。

或者您可以自己找到 DLL 并将其放在搜索路径或与可执行文件相同的文件夹中。

关于postgresql - 从 Cygwin 在 C 中运行 PostgreSQL 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13213545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com