【问题标题】:Compiling C in Windows XP在 Windows XP 中编译 C
【发布时间】:2010-09-17 13:47:10
【问题描述】:

我想学习 Vim 编辑器,我正在尝试编译一个 C 文件。我已经安装了 MinGW 并将 gcc.exe 添加到系统路径:

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Arquivos de programas\TortoiseSVN\bin;c:\Arquivos de programas\Microsoft SQL Server\100\Tools\Binn\;c:\Arquivos de programas\Microsoft SQL Server\100\DTS\Binn\;C:\MinGW\bin\

在 Vim 中,我做了: :!gcc code.c -o gcc.exe 一个 cmd 窗口打开并显示以下文本:

C:\WINDOWS\system32\cmd.exe /c gcc -Wall code.c -o code.exe
gcc: code.c: No such file or directory
gcc: no input files
shell returned 1
Hit any key to close this window...

怎么了? 谢谢。

【问题讨论】:

  • 需要从code.c所在的目录执行命令。
  • 也许你试图编译的程序调用了 UB(或者为什么这被标记为“c”?)
  • C:\code.c - 如何更改目录然后在 vim 中运行?

标签: c vim gcc windows-xp path


【解决方案1】:

完整的.vimrcthis question,你需要的行是:

" Automatically cd into the directory that the file is in
autocmd BufEnter * execute "chdir ".escape(expand("%:p:h"), ' ')

【讨论】:

  • 很酷。它真的很有效!谢谢!你能解释一下这条线吗?
  • 其实...没有 :) 我没有打扰它,我只是使用它 - 但 :help 是你的朋友,autocmd 命令在 40.3 中介绍
【解决方案2】:

您的文件是否可能实际上命名为“code.c.something”。 Windows 喜欢在不询问的情况下为文件添加额外的结尾。这可能不是解决方案,但需要注意。

【讨论】:

  • 您从哪里得知 Windows 喜欢这样做?
  • Windows 中的默认样式设置将隐藏文件扩展名并在您保存文件时自动添加文件扩展名。如果您允许隐藏所有文件扩展名,那么您将不知道文件的名称。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-12
相关资源
最近更新 更多