简体   繁体   English

为什么我的C程序可以在“git bash”中运行,但不能在“cmd”中运行?

[英]Why can my C program run in "git bash", but not in "cmd"?

I wrote a demo using libpq to connect to a PostgreSQL database.我写了一个使用 libpq 连接到 PostgreSQL 数据库的演示。

I tried to connect the C file to PostgreSQL by including我试图通过包含将 C 文件连接到 PostgreSQL

#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:在我将路径添加到系统变量I:\Program Files\PostgreSQL\12\lib以及I:\Program Files\PostgreSQL\12\include并使用此命令编译后:

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我把这三个文件下载下来放到I:\Program Files\PostgreSQL\12\lib ,重新编译后,就报错了

The application was unable to start correctly (0xc0150002)

when I type testpsql .当我输入testpsql时。 But if I type ./testpsql on git bash, it works.但是如果我在 git bash 上输入./testpsql ,它就可以工作。 Anyone can please tell me why?谁能告诉我为什么?

The code that I used was the first example from here .我使用的代码是此处的第一个示例。

Environment: PostgreSQL 12, Windows 10, MinGW64环境:PostgreSQL 12、Windows 10、MinGW64

“Download the DLL files” sounds dangerous. “下载 DLL 文件”听起来很危险。 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).由于您可能没有从您的代码中引用这些库,它必须是libpq.dll的依赖项并且可能在I:\Program Files\PostgreSQL\12\bin中找到(如果您使用了 EDB 安装程序)。

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 .问题可能是您的PATH环境变量在git bashcmd.exe中不同,在后一种情况下,并非所有必需的共享库都可以在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 ,使其包含可执行文件所需的所有 DLL 文件,而不是开始复制文件。

It is probably enough to include I:\Program Files\PostgreSQL\12\bin in the PATH .PATH中包含I:\Program Files\PostgreSQL\12\bin可能就足够了。 To resolve missing dependencies, use a tool like dependency walker or this replacement .要解决缺少的依赖项,请使用dependency walker此替换工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM