问题
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
回答1:
“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.
来源:https://stackoverflow.com/questions/59087525/why-can-my-c-program-run-in-git-bash-but-not-in-cmd