c - Bash for Windows 10 gcc 不会编译粘贴到根目录中的 c 文件

标签 c bash ubuntu gcc windows-10

顾名思义,如果我把一个写在别处的c文件粘贴到Linux子系统的根目录下,我无法编译它。

我做了一个测试,我制作了两个不同名称的 hello world 程序:一个在 vi 中,我可以从 bash 界面进入,另一个在其他地方。当我编译用 vi 制作的那个时,它运行良好。尝试对在别处制作的文件执行此操作(在将其粘贴到根目录后),然而,结果如下:

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

如有任何帮助,我们将不胜感激。

最佳答案

Do not change Linux files using Windows apps and tools!

假设您所说的“将在其他地方编写的 C 文件粘贴到 Linux 子系统的根目录中”的意思是您将文件粘贴到 %localappdata%\lxss 中,这是 明确不受支持。在此区域中通过 Linux 系统调用本地创建的文件具有 UNIX 元数据,而使用 Windows 工具本地创建的文件则没有。

使用 /mnt/c(以及类似的)从 Linux 访问您的 Windows 文件;不要尝试从 Windows 修改 Linux 文件。


引自此答案顶部链接的 Microsoft 博客(强调原文):

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

关于c - Bash for Windows 10 gcc 不会编译粘贴到根目录中的 c 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44312116/

相关文章:

bash - 从 shell 脚本执行 Maven 任务并获取错误代码

c++ - Arcsynthesis OpenGL 3.3 教程的问题 - MAKE 错误

docker - 如何使用 apparmor 在 docker 容器中启用挂载文件系统

linux - 如何跳过/dev/sda1 : clean in booting system?

c++ - 为什么 `(a--> 0)` 和 `((a--) > 0)` 相同?

c++ - C语言中宏的使用

bash - 基本流/sed? bash 脚本,在每一行执行子字符串

python - 我正在尝试使用 shell 命令在 python 中发送邮件。但变量不会在脚本中被替换

c - 使用glade将用户数据传递给回调函数

c - 调试程序运行另一个程序