gcc fails with spawn: No such file or directory

后端 未结 7 2220
醉梦人生
醉梦人生 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:03

    I had the same error when I tried to extract a couple of executables from cygwin installation dirctory and copied them into another location.

    strace shows me the file which was not found by spawn:

    /lib/gcc/x86_64-pc-cygwin/6.4.0/cc1.exe
    

    When I copied cc1.exe into the location relative to

    <dir with sh.exe and cpp.exe>/../lib/gcc/x86_64-pc-cygwin/6.4.0/cc1.exe
    

    it works fine.

    0 讨论(0)
  • 2021-02-13 14:04

    Ruben's builds are not Cygwin GCC packages, rather they are cross-compilers which run on various platforms but target native Windows using the MinGW-w64 toolchain.

    In any case, you shouldn't be using them on Cygwin. If you want to compile Cygwin executables, install the gcc4 packages; if you want to cross-compile for Windows, install the mingw64-i686-gcc (for Win32) or mingw64-x86_64-gcc (for Win64) packages instead.

    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2021-02-13 14:06

    I had this same problem on Cygwin64, and the solution was PATH related..kinda.

    Turns out, there are copies of gcc in /usr/bin and /bin (at least, there is in my install).

    Executing /bin/gcc failed with the error above -- I'm guessing due to incorrectly assumed relative paths???

    Executing /usr/bin/gcc works as expected!

    In my case, the "problem" was that I had inadvertently injected "/bin" into my PATH environment variable, resulting in /bin/gcc being executed, instead of /usr/bin/gcc. Removing the "/bin" from the path solved the problem.

    Still unclear why there are two gcc binaries (which appear to be identical) in different places... but maybe the Cygwin gurus can answer that; or maybe my installation is just foo-barred.

    0 讨论(0)
  • 2021-02-13 14:15

    I had the same problem and solved it by installing the g++ package in addition to gcc-core

    0 讨论(0)
  • 2021-02-13 14:21

    Make sure the source file extension is in lowercase (i.e. main.c, not main.C):

    $ gcc -o main main.C
    $ gcc: error: spawn: No such file or directory
    
    $ gcc -o main main.c
    $ # all good
    

    This only refers to the case of the extension as given to the gcc, the actual source file can have the extension in whatever case you want.

    Explanation: This is from my experimenting with cygwin and gcc, I don't know the actual reason for this behavior.

    0 讨论(0)
提交回复
热议问题