ubuntu下ansi-c和gcc的初学者问题/错误

发布于 2024-08-31 00:15:34 字数 1665 浏览 10 评论 0原文

我刚刚开始在 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下的编程新手。我在谷歌上搜索帮助并浏览了教程,但无法找到答案。谢谢你!

代码:

/* 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 

I am just starting programming ansi c with gcc under ubuntu (9.04). I get following error messages:

error messages:

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

I assume it is a very simple problem, maybe in the configuration of ubuntu or gcc. I am new to programming under linux as well. I googled for help and went through a tutorial but could not find an answer. Thank you!

code:

/* 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);
    }

command:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

从来不烧饼 2024-09-07 00:15:35

您真的确定您显示的代码是您实际正在编译的代码吗?您会收到错误:

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

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

Are you really sure that the code you show is the code you are actually compiling? You get the error:

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

but the code doesn't actually have 12 lines in it.

—━☆沉默づ 2024-09-07 00:15:35

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

I used "//" to comment lines, which ansi-c does not like.
Thank you all for your input!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文