C语言 PostgreSQL 错误:程序无法启动,因为您的计算机缺少 libpq.dll
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20412084/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PostgreSQL Error: The program can't start because libpq.dll is missing from your computer
提问by CodyBugstein
I'm using Visual Studio 2010 to build a program in Cthat can operate on a PostgreSQL database.
我正在使用 Visual Studio 2010 构建一个C可以在 PostgreSQL 数据库上运行的程序。
Everything is fine in VS, no compile errors, everything looks good.
在 VS 中一切正常,没有编译错误,一切看起来都不错。
When I click to debug and run, the code compiles, but then I get a pop up that says:
当我单击调试并运行时,代码会编译,但随后我会弹出一个窗口,显示:
The program can't start because libpq.dll is missing from your computer
The program can't start because libpq.dll is missing from your computer
I've installed PostgreSQL and added the folder containing all the necessary files to my includeand linkerpaths, but to no avail.
I cannot figure out why I am still getting this message?
我已经安装了 PostgreSQL 并将包含所有必要文件的文件夹添加到我的include和linker路径中,但无济于事。我不明白为什么我仍然收到这条消息?
Any suggestions?
有什么建议?
回答by Phorkus Maximus
The answer's surprisingly simple.
答案出奇的简单。
The issue you're seeing comes from the compiled application not being able to find the PostgreSQL libraries. The libpq.lib is used to compile the application, and it links to the DLL at run-time. You can either add it to your system wide path, or bundle the DLL with your application. (I'd add it on the development machine, and bundle the redistributable for a installer package.)
您看到的问题来自编译的应用程序无法找到 PostgreSQL 库。libpq.lib 用于编译应用程序,并在运行时链接到 DLL。您可以将其添加到系统范围的路径中,也可以将 DLL 与您的应用程序捆绑在一起。(我会将它添加到开发机器上,并为安装程序包捆绑可再发行组件。)
To include it in your path try:
要将其包含在您的路径中,请尝试:
- Right click on "My Computer" and select Properties
- Then Click on "Advanced System Settings".
- Click the "Environment Variables" button at the bottom of the dialog box.
- It will pop up a dialog with a group box labeled "System Variables". Find the one in the list box that has a Variable name of "Path".
- Now, add the path of the PostgreSQL library folder to the path with a ";" separator.
- Now logout or reboot. It's imperativethat you at least log out of Windows and log back in for the Visual Studio debugger to pickup the additional executable module paths (that Path variable). Ideally, rebooting sends the new system path to all applications in the system at boot time.
- 右键单击“我的电脑”并选择属性
- 然后点击“高级系统设置”。
- 单击对话框底部的“环境变量”按钮。
- 它将弹出一个对话框,其中包含一个标记为“系统变量”的组框。在列表框中找到变量名称为“Path”的那个。
- 现在,将 PostgreSQL 库文件夹的路径添加到带有“;”的路径中 分隔器。
- 现在注销或重新启动。您必须至少注销 Windows 并重新登录,以便 Visual Studio 调试器获取附加的可执行模块路径(该 Path 变量)。理想情况下,重新引导会在引导时将新系统路径发送到系统中的所有应用程序。
If the Path variable has "C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem" in it, you would add ";C:\Program Files\PostgreSQL\libraries" to make it look like "C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files\PostgreSQL\libraries".
如果 Path 变量中有 "C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem",你可以添加 ";C:\Program Files\PostgreSQL\libraries" 使其看起来像“C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files\PostgreSQL\libraries”。
Be aware that your path will be reallylong in most cases. Just add it to the end.
请注意,在大多数情况下,您的路径会很长。只需将其添加到最后即可。
Good luck!
祝你好运!
回答by Lubo? Mi?atsky
I have Win10 64 bit and this worked for me.
我有 Win10 64 位,这对我有用。
Get portable version of HeidiSQL and copy libpg.dll from the archive to the HeidiSQL installation folder on your computer.
获取 HeidiSQL 的便携版本并将 libpg.dll 从存档复制到您计算机上的 HeidiSQL 安装文件夹。
Works like a charm.
奇迹般有效。

