I wrote a demo using libpq to connect to a PostgreSQL database.
I tried to connect the C file to PostgreSQL by including
#include <libpq-fe.h>
after I added the paths into system variables I:\Program Files\PostgreSQL\12\lib
as well as to I:\Program Files\PostgreSQL\12\include
and compiled with this command:
gcc -Wall -Wextra -m64 -I "I:\Program Files\PostgreSQL\12\include" -L "I:\Program Files\PostgreSQL\12\lib" testpsql.c -lpq -o testpsql
It first raised three errors, like
libssl-1_1-x64.dll is missing
libintl-8.dll was missing
libcrypto-1_1-x64.dll was missing
After I downloaded these three files and put them into I:\Program Files\PostgreSQL\12\lib
, and compiled it again, it shows the error
The application was unable to start correctly (0xc0150002)
when I type testpsql
. But if I type ./testpsql
on git bash, it works. Anyone can please tell me why?
The code that I used was the first example from here .
Environment: PostgreSQL 12, Windows 10, MinGW64
“Download the DLL files” sounds dangerous. From where?
I would get rid of these files again. Since you probably don't reference these libraries from your code, it must be the dependencies of libpq.dll
and are probably found in I:\Program Files\PostgreSQL\12\bin
(if you used the EDB installer).
The problem is probably that you the PATH
environment variable is different in git bash
and in cmd.exe
, and in the latter case not all required shared libraries can be found on the PATH
. The solution is to change the PATH
so that it includes all DLL files the executable requires, not to start copying around files.
It is probably enough to include I:\Program Files\PostgreSQL\12\bin
in the PATH
. To resolve missing dependencies, use a tool like dependency walker or this replacement .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.