Search code examples
cwindowscmdmingw-w64

Cmd cannot run my executable without providing ".exe"


So I have compiled & linked a program called "embed.exe" using mingw gcc compiler but it I am required by cmd to use "embed.exe" instead of "embed" to run it.

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>

I want to be able to run it by typing "embed" only. This only happens to my program. Yes, the pathext does contain .exe.
So this has made me think there's something wrong with mingw output, as if cmd doesn't recognize that it's an exe if I don't specify .exe.

Here are all my compiler flags:

-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

Solution

  • Turns out the problem is not with mingw but with how I create the bin directory. The problem occurs when I use bash on windows to mkdir the directory, but if I use windows' mkdir, it works. Who would've thought...

    How to reproduce the error:

    Directory:

    embed
        |-->main.c
    

    Cd to embed directory.

    > 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 back and delete bin

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