所以我使用 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”来运行它。这仅发生在我的程序中。是的,路径文本确实包含 .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
最佳答案
事实证明问题不在于 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>
关于如果不提供 ".exe",Cmd 无法运行我的可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53546760/