Why can my C program run in “git bash”, but not in “cmd”?

社会主义新天地 提交于 2020-01-25 08:16:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!