gcc fails with spawn: No such file or directory

后端 未结 7 2237
醉梦人生
醉梦人生 2021-02-13 13:41

I downloaded Ruben’s build of Cygwin GCC.

However upon running it seems unable to compile any files

$ touch foo.c

$ gcc foo.c
gcc: error: spawn: No such file         


        
7条回答
  •  礼貌的吻别
    2021-02-13 14:04

    This error occurs whenever cygwin cc can't find a required file.

    For those running stuff within cygwin's bin directly from a Windows shell, a gotcha to watch out for is that Windows allow you to run programs from the command line like this:

    e:cyg/bin/gcc -flags
    

    Notice that there is no slash between e: and cyg.

    So this command would successfully start cygwin gcc from the Windows shell, but halfway through the run it will error out because some component(s) of gcc will utilize the first argument of the input e:cyg/bin/gcc and unlike mingw, this is not a valid path for cygwin gcc.

    This can be fixed simply by changing the command to:

    e:/cyg/bin/gcc -flags
    

    Notice the slash in between e: and cyg.


    A similar gotcha is due to Windows allowing paths like e:/../folder1 as an alternative to e:/folder1. Windows does not give you an error if you are at the root folder and try to go up another folder using ...

    So you could start running cygwin gcc using the command:

    e:/../cyg/bin/gcc -flags
    

    ..or even:

    e:/../../../../../../../../../cyg/bin/gcc -flags
    

    However, it would fail halfway with gcc: error: spawn: No such file or directory because some component(s) of cygwin gcc would attempt to run gcc using the first argument of the command input itself, and unlike mingw, e:/../cyg/bin/gcc is not recognized as a valid path by cygwin because you are going up a folder when there's no folder to go up to.

    As like above, this can be fixed by keeping the path valid:

    e:/cyg/bin/gcc -flags
    

提交回复
热议问题