如果没有提供“.exe”,Cmd无法运行我的可执行文件

问题描述 投票:0回答:2

所以我使用mingw gcc编译器编译并链接了一个名为“embed.exe”的程序,但我要求cmd使用“embed.exe”而不是“embed”来运行它。

D:\c\embed\bin\release>embed
'embed' is not recognized as an internal or external command,
operable program or batch file.

D:\c\embed\bin\release>embed.exe  
Usage: embed [-h] <input>

我想通过只键入“embed”来运行它。这只发生在我的程序中。是的,pathext确实包含.exe。 所以这让我觉得mingw输出有问题,就好像我没有指定.exe那样cmd不能识别它是一个exe。

这是我的所有编译器标志:

-std=gnu11 -march=x86-64 -msse3 
-Werror -Wall -Wextra -Wno-unused-parameter -Wno-missing-braces 
-Wno-missing-field-initializers -Wpedantic -Wno-format 
-flto 
-g -D_DEBUG -DDEBUG -Og 
-Wl,-subsystem,console
c windows cmd mingw-w64
2个回答
1
投票

事实证明问题不在于mingw,而在于我如何创建bin目录。当我在windows上使用bash来mkdir目录时会出现问题,但是如果我使用windows的mkdir,它就可以了。谁会想到......

如何重现错误:

目录:

embed
    |-->main.c

cd来嵌入目录。

> gcc -c main.c -o main.o
> bash -c "mkdir bin"
> gcc -o bin/embed.exe main.o -Wl,-subsystem,console
> cd bin
> embed
'embed' is not recognized as an internal or external command,
operable program or batch file.

Cd返回并删除bin

> mkdir bin
> gcc -o bin/embed.exe main.o -Wl,-subsystem,console
> cd bin
> embed
Usage: embed [-h] <input>

-1
投票

阅读PATHEXT。 。 。它是一个可选的CMD环境变量,可以帮助您。

事实上,如果* .EXE文件不起作用,我猜你可能已经有了该变量,并且它不包含列表中的EXE。

坦率

© www.soinside.com 2019 - 2024. All rights reserved.