使用 C++ 与 libpq 发生链接错误

发布于 2024-10-22 13:05:46 字数 770 浏览 5 评论 0原文

我正在尝试使用 libpq 连接到我的 PostgreSQL 数据库,并打算在开始工作后调用预定义的函数。现在我只需输入 conninfo 字符串,然后测试连接。最终弄清楚如何在我的项目中包含不同的代码目录和库路径(Windows 7 上的 Netbeans 6.9.1,MinGW 编译器)后,我发现此错误:

g++.exe -c -I/C/Program\ Files/PostgreSQL/9.0/include -MMD -MP -MF build/Debug/MinGW-Windows/main.od -o build/Debug/MinGW-Windows/main .o main.cpp

mkdir -p dist/Debug/MinGW-Windows

g++.exe -o dist/Debug/MinGW-Windows/toolboxconnect build/Debug/MinGW-Windows/main.o -L/C/Program\ Files/PostgreSQL/9.0/lib -lpq

c:/Program Files/PostgreSQL/9.0/lib/libpq.dll:文件无法识别:文件格式无法识别
collect2:ld返回1退出状态

我搜索了很多主题来查找无法识别的原因,但人们向其他人建议这是因为它们运行的​​是 64 位,并且需要重建 dll。我认为我的 PostgreSQL 安装没有附带 makefile 来重新编译这些文件,并且假设它们按原样使用就很好。还有其他原因导致我的链接器不喜欢我的 libpq 库/其他类型的修复吗?

I'm trying to use libpq to connect to my PostgreSQL database and intend to call pre-defined functions once I get this working. Right now I just have the conninfo string entered, and test the connection. After finally figuring out how to include different code directories and library paths (Netbeans 6.9.1 on Windows 7, MinGW compiler) in my project, I find this error:

g++.exe -c -I/C/Program\ Files/PostgreSQL/9.0/include -MMD -MP -MF build/Debug/MinGW-Windows/main.o.d -o build/Debug/MinGW-Windows/main.o main.cpp

mkdir -p dist/Debug/MinGW-Windows

g++.exe -o dist/Debug/MinGW-Windows/toolboxconnect build/Debug/MinGW-Windows/main.o -L/C/Program\ Files/PostgreSQL/9.0/lib -lpq

c:/Program Files/PostgreSQL/9.0/lib/libpq.dll: file not recognized: File format not recognized
collect2: ld returned 1 exit status

I have searched many topics for the reason of why this could not be recognized, but people suggest to others that its because theyre running 64-bit, and would need to rebuild the dlls. I don't think my PostgreSQL install came with makefiles to recompile these, and assumed they would be good to use as they were. Is there any other reason why my linker would not like my libpq library/some other sort of fix?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妄想挽回 2024-10-29 13:05:46

其他人刚刚对 libpq 遇到了类似的问题。

根据该答案之后的讨论,这里有一个下载源代码 这样您就可以重建它以满足您的需要。有不同的版本可用,因此请确保下载您想要的版本。

我真的不想让你陷入依赖地狱“你的依赖不起作用?下载源代码并自己重新编译它!” ——但遗憾的是,这似乎是目前 postgres 的唯一选择。

Someone else just had a similar issue with libpq.

From the discussion that followed that answer, here's a link to download the source code so you can rebuild it to suit your needs. There are different versions available, so make sure you download the one you want.

I really hate to just stick you with the dependency hell of "Your dependency doesn't work? Download the source and recompile it yourself!" -- but sadly, that seems to be the only option for postgres at the moment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文