CodyBugstein
CodyBugstein

Reputation: 23322

PostgreSQL Error: The program can't start because libpq.dll is missing from your computer

I'm using Visual Studio 2010 to build a program in C that can operate on a PostgreSQL database.

Everything is fine in VS, no compile errors, everything looks good.

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

I've installed PostgreSQL and added the folder containing all the necessary files to my include and linker paths, but to no avail. I cannot figure out why I am still getting this message?

Any suggestions?

Upvotes: 15

Views: 44383

Answers (4)

Adam
Adam

Reputation: 73

The selected answer is in the right direction, but didn't work for me. I would have just commented on it, but I don't have the XP to do that. For me, I had to add:

C:\Program Files\PostgreSQL\16\bin

and

C:\Program Files\PostgreSQL\16\include

to the PATH variable to get it to work (based on hours of going in circles and stumbling across this suggestion elsewhere).

TBH - I'm not totally sure which one got it to work, I didn't remove either to find out. But the Libraries certainly didn't work for me and somewhere in my research I saw a note about each of these using the same logic as above.

Upvotes: 1

Peter Steiner
Peter Steiner

Reputation: 13

Using the latest PostgreSQL 16 client installation, you need to copy the following additional libraries to successfully load libpq.dll:

libssl-3-x64.dll
libcrypto-3-x64.dll
libintl-9.dll
libiconv-2.dll
libwinpthread-1.dll

Note that the last two dependencies seem to be dynamically loaded and do not show in dumpbin.exe inspection. You can temporarily use psql.exe to receive feedback on the missing libraries though.

Upvotes: 0

Luboš Miřatský
Luboš Miřatský

Reputation: 1619

I have Win10 64 bit and this worked for me.

Get portable version of HeidiSQL and copy libpg.dll from the archive to the HeidiSQL installation folder on your computer.

Works like a charm.

Upvotes: 2

Phorkus Maximus
Phorkus Maximus

Reputation: 416

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.)

To include it in your path try:

  1. Right click on "My Computer" and select Properties
  2. Then Click on "Advanced System Settings".
  3. Click the "Environment Variables" button at the bottom of the dialog box.
  4. 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".
  5. Now, add the path of the PostgreSQL library folder to the path with a ";" separator.
  6. Now logout or reboot. It's imperative that 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.

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".

Be aware that your path will be really long in most cases. Just add it to the end.

Good luck!

Upvotes: 20

Related Questions