0

我写了一个非常简单的程序,例如:(对不起,我以正确的方式输入了代码,但是显示器是有线的。我该如何解决?)

#include <stdio.h>
int main( void )
{
   int i;

   for ( i = 0; i <= 10; i++ ) {
      printf( "%d hello!\n", i);
   }
   return 0;
}

通常,我在终端中使用命令编译 c 程序

cc -o xxx xxx.c

所以在 Emacs 中,当我键入 Mx compile 时,我将 make -k 更改为 cc -o。但我得到了错误

cc: '-o' 的参数丢失

有什么问题?

如果我使用make,那么我仍然得到错误

没有指定目标,也没有找到任何生成文件。

最后,如果上述问题得到解决,我该如何定义自定义热键进行编译?我已经知道该怎么做

全局设置键 [f8] '转到行

但我不知道仅为 c 模式设置一个动作的热键。

4

4 回答 4

2

您需要提供整个 cc 行。

“make -k”假设你有一个 Makefile 提供命令来制作东西。

因此,将 make -k 替换为

cc -o xxx xxx.c

至于 emacs 绑定:

(global-set-key [f6] 'compile)
于 2011-01-07T07:20:55.853 回答
1

构建像这样的简单单文件程序的一种好方法是在文件顶部为 compile-command 变量添加值,如下所示:

// -*- compile-command:"g++ helloworld.cpp -g -o helloworld.exe"; -*-

在我的博客文章“在没有 makefile 的情况下在 emacs 中编写快速 C++ 程序”中有更多详细信息

于 2011-01-08T19:50:10.340 回答
0

I think a good way of doing it is like it is documented for the variable compile-command (which is the one used by compile, normally containing make -k).

Do C-h v compile-command to see the documentation for the variable. It contains some code that you can change to your liking.

于 2011-01-07T17:35:01.767 回答
0

尝试更改 make -k 以制作 xxx。

于 2011-01-07T07:51:21.163 回答