Bash for Windows 10 gcc won't compile c files pasted into the root directory

最后都变了- 提交于 2019-12-02 15:58:06

问题


As the title suggests, if I paste a c file written somewhere else into the root directory of the Linux Subsystem, I can't compile it.

I did a test where I made two differently titled hello world programs: one in vi that I can get into from the bash interface, and one elsewhere. When I compiled the one made in vi, it worked fine. Trying to do so for the one made elsewhere (after pasting it into the root directory), however, resulted in this:

gcc: error: helloWorld2.c: Input/output error
gcc: fatal error: no input files
compilation terminated

Any help with this would be much appreciated.


回答1:


Do not change Linux files using Windows apps and tools!

Assuming what you meant by "paste a C file written somewhere else into the root directory of the Linux subsystem" is that you pasted your file into %localappdata%\lxss, this is explicitly unsupported. Files natively created via Linux syscalls in this area have UNIX metadata, which files natively created with Windows tools don't have.

Use /mnt/c (and the like) to access your Windows files from Linux; don't try to modify Linux files from Windows.


Quoting from the Microsoft blog linked at the top of this answer (emphasis from the original):

Therefore, be sure to follow these two rules in order to avoid losing files, and/or corrupting your data:

  • DO store files in your Windows filesystem that you want to create/modify using Windows tools AND Linux tools
  • DO NOT create / modify Linux files from Windows apps, tools, scripts or consoles



回答2:


You cannot copy (by default, who knows how Windows bash is set up!) files into the root directory! Your gcc error is say "no input files", so the copy has most likely failed. Copy the files to your home directory instead, for instance:

cp helloWorld2.c ~/

instead of:

cp helloWorld2.c /


来源:https://stackoverflow.com/questions/42941023/bash-for-windows-10-gcc-wont-compile-c-files-pasted-into-the-root-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!