【问题标题】:Beginner problem / error with ansi-c and gcc under ubuntuubuntu下ansi-c和gcc的初学者问题/错误
【发布时间】:2010-04-26 11:40:00
【问题描述】:

我刚刚开始在 ubuntu (9.04) 下使用 gcc 编写 ansi c。我收到以下错误消息:

错误消息:

main.c:6: error: expected identifier or ‘(’ before ‘/’ token
In file included from /usr/include/stdio.h:75,
                 from main.c:9:
/usr/include/libio.h:332: error: expected specifier-qualifier-list before ‘size_t’
/usr/include/libio.h:364: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/libio.h:373: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/libio.h:493: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_IO_sgetn’
In file included from main.c:9:
/usr/include/stdio.h:314: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdio.h:682: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fread’
/usr/include/stdio.h:688: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fwrite’
main.c:12: error: expected identifier or ‘(’ before ‘/’ token

我认为这是一个非常简单的问题,可能在 ubuntu 或 gcc 的配置中。我也是linux下编程的新手。我搜索了帮助并通过tutorial 但找不到答案。谢谢!

代码:

/* cheat with the preprocessor to skip over missing lines to attempt
   to duplicate the circumstance of the original code */
#line 9
// #include <some_random_header.h>
#include <stdio.h>
#include <math.h>    
int main(int argc, char **argv)
    {
     printf("TestOutput\n");

     return (0);
    }

命令:

~/Documents/projects/Trials$ gcc -Wall -ansi main.c

【问题讨论】:

  • 首先简化 - 删除 '#include ',然后做一个简单的 gcc main.c - 请修复你的 main,它应该是 int main(int argc, char **argv )
  • 我用“//”来注释行,这是ansi-c不喜欢的。谢谢大家的意见!
  • 那么,只是出于好奇,当您甚至没有将代码发布到真正的问题上时,应该如何帮助您解决问题?
  • 那么,只是出于好奇,你想如何帮我讽刺一下?
  • 这是一个真正的问题 - 需要指出,以便其他人可以从中学习。在你的情况下,我注意到你选择攻击而不是'mea culpa',而不是像这样的错误之后最明智的选择。

标签: gcc ubuntu path linker ansi


【解决方案1】:

您确定您显示的代码就是您实际编译的代码吗?你得到错误:

main.c:12: error: expected identifier or ‘(’ before ‘/’ token

但代码实际上并没有 12 行。

【讨论】:

  • 它在任何地方都没有/ 令牌。
  • 我评论了一些行以提供一个最小的示例。但事实证明这是问题所在。 Ansi-C 不喜欢“//”。
【解决方案2】:

我使用“//”来注释行,这是 ansi-c 不喜欢的。 谢谢大家的意见!

【讨论】:

  • 尽管它是我问题的答案?
  • 欢迎来到 stackoverflow.com ;-)
  • +1 鼓励记录实际问题的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-11
相关资源
最近更新 更多