为什么我的C程序可以在"git bash"中运行,而不能在"cmd"中运行? [英] Why can my C program run in "git bash", but not in "cmd"?
问题描述
我使用libpq编写了一个演示以连接到PostgreSQL数据库.
I wrote a demo using libpq to connect to a PostgreSQL database.
我试图通过包含将C文件连接到PostgreSQL
I tried to connect the C file to PostgreSQL by including
#include <libpq-fe.h>
将路径添加到系统变量I:\Program Files\PostgreSQL\12\lib
和I:\Program Files\PostgreSQL\12\include
中并使用以下命令编译后:
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
下载这三个文件并将它们放入I:\Program Files\PostgreSQL\12\lib
,然后再次编译后,它显示错误
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)
当我键入testpsql
时.但是,如果我在git bash上键入./testpsql
,它将起作用.有人可以告诉我为什么吗?
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.
环境:PostgreSQL 12,Windows 10,MinGW64
Environment: PostgreSQL 12, Windows 10, MinGW64
推荐答案
“下载DLL文件”听起来很危险.从哪里来?
“Download the DLL files” sounds dangerous. From where?
我会再次删除这些文件.由于您可能未从代码中引用这些库,因此它必须是libpq.dll
的依赖项,并且可能在I:\Program Files\PostgreSQL\12\bin
中找到(如果使用了EDB安装程序).
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).
问题可能是您的PATH
环境变量在git bash
和cmd.exe
中是不同的,在后一种情况下,不能在PATH
上找到所有必需的共享库.解决方案是更改PATH
,使其包含可执行文件所需的所有DLL文件,不开始在文件周围进行复制.
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.
在PATH
中包含I:\Program Files\PostgreSQL\12\bin
可能就足够了.要解决缺少的依赖关系,请使用 dependency walker 或
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.
这篇关于为什么我的C程序可以在"git bash"中运行,而不能在"cmd"中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!