LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 944|回复: 10

helloword请教

[复制链接]
发表于 2005-5-1 16:57:48 | 显示全部楼层 |阅读模式
我的hello.c:
#include <stdio.h>
main()
{
  printf("hello,word\n");
}

编译输入:gcc -o hello hello.c,编译提示如下:
luopeng@ubuntu:~/c$ gcc -o hell hello.c
hello.c:1: error: syntax error before "buffer"
hello.c:1:36: missing terminating ' character
hello.c:1:36: warning: character constant too long for its type
hello.c:2: error: syntax error before "you"
hello.c:2: error: syntax error before "that"
hello.c:3: error: syntax error before "enter"
hello.c:3:36: missing terminating ' character
hello.c:3:36: warning: character constant too long for its type
In file included from /usr/include/_G_config.h:44,
                 from /usr/include/libio.h:32,
                 from /usr/include/stdio.h:72,
                 from hello.c:5:
/usr/include/gconv.h:72: error: syntax error before "size_t"
/usr/include/gconv.h:88: error: syntax error before "size_t"
/usr/include/gconv.h:97: error: syntax error before "size_t"
/usr/include/gconv.h:174: error: syntax error before "size_t"
/usr/include/gconv.h:177: error: syntax error before '}' token
In file included from /usr/include/libio.h:32,
                 from /usr/include/stdio.h:72,
                 from hello.c:5:
/usr/include/_G_config.h:47: error: field `__cd' has incomplete type
/usr/include/_G_config.h:50: error: field `__cd' has incomplete type
In file included from /usr/include/stdio.h:72,
                 from hello.c:5:
/usr/include/libio.h:351: error: syntax error before "size_t"
/usr/include/libio.h:360: error: syntax error before "size_t"
/usr/include/libio.h:468: error: syntax error before "_IO_sgetn"
/usr/include/libio.h:468: error: syntax error before "size_t"
In file included from hello.c:5:
/usr/include/stdio.h:302: error: syntax error before "size_t"
/usr/include/stdio.h:309: error: syntax error before "size_t"
/usr/include/stdio.h:351: error: syntax error before "size_t"
/usr/include/stdio.h:355: error: syntax error before "size_t"
/usr/include/stdio.h:603: error: syntax error before "fread"
/usr/include/stdio.h:603: error: syntax error before "size_t"
/usr/include/stdio.h:609: error: syntax error before "fwrite"
/usr/include/stdio.h:609: error: syntax error before "size_t"
/usr/include/stdio.h:631: error: syntax error before "fread_unlocked"
/usr/include/stdio.h:631: error: syntax error before "size_t"
/usr/include/stdio.h:633: error: syntax error before "fwrite_unlocked"
/usr/include/stdio.h:633: error: syntax error before "size_t"
/usr/include/gconv.h:176: warning: array `__data' assumed to have one element
这是什么错误,是不是编程环境没有配置好?
发表于 2005-5-1 17:44:34 | 显示全部楼层
你用的是bsd系统?
加一行在最前面:
#include <sys/types.h>
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-5-2 11:24:00 | 显示全部楼层
我用的是ubuntu。一个基于debian的系统。加了后提示还是一样啊。
luopeng@ubuntu:~/c$ gcc -o hello hello.c
hello.c:1: error: syntax error before "buffer"
hello.c:1:36: missing terminating ' character
hello.c:1:36: warning: character constant too long for its type
hello.c:2: error: syntax error before "you"
hello.c:2: error: syntax error before "that"
hello.c:3: error: syntax error before "enter"
hello.c:3:36: missing terminating ' character
hello.c:3:36: warning: character constant too long for its type
In file included from /usr/include/_G_config.h:44,
                 from /usr/include/libio.h:32,
                 from /usr/include/stdio.h:72,
                 from hello.c:5:
/usr/include/gconv.h:72: error: syntax error before "size_t"
/usr/include/gconv.h:88: error: syntax error before "size_t"
/usr/include/gconv.h:97: error: syntax error before "size_t"
/usr/include/gconv.h:174: error: syntax error before "size_t"
/usr/include/gconv.h:177: error: syntax error before '}' token
In file included from /usr/include/libio.h:32,
                 from /usr/include/stdio.h:72,
                 from hello.c:5:
/usr/include/_G_config.h:47: error: field `__cd' has incomplete type
/usr/include/_G_config.h:50: error: field `__cd' has incomplete type
In file included from /usr/include/stdio.h:72,
                 from hello.c:5:
/usr/include/libio.h:351: error: syntax error before "size_t"
/usr/include/libio.h:360: error: syntax error before "size_t"
/usr/include/libio.h:468: error: syntax error before "_IO_sgetn"
/usr/include/libio.h:468: error: syntax error before "size_t"
In file included from hello.c:5:
/usr/include/stdio.h:302: error: syntax error before "size_t"
/usr/include/stdio.h:309: error: syntax error before "size_t"
/usr/include/stdio.h:351: error: syntax error before "size_t"
/usr/include/stdio.h:355: error: syntax error before "size_t"
/usr/include/stdio.h:603: error: syntax error before "fread"
/usr/include/stdio.h:603: error: syntax error before "size_t"
/usr/include/stdio.h:609: error: syntax error before "fwrite"
/usr/include/stdio.h:609: error: syntax error before "size_t"
/usr/include/stdio.h:631: error: syntax error before "fread_unlocked"
/usr/include/stdio.h:631: error: syntax error before "size_t"
/usr/include/stdio.h:633: error: syntax error before "fwrite_unlocked"
/usr/include/stdio.h:633: error: syntax error before "size_t"
In file included from /usr/include/sys/types.h:266,
                 from hello.c:6:
/usr/include/bits/pthreadtypes.h:50: error: syntax error before "size_t"
/usr/include/bits/pthreadtypes.h:53: error: syntax error before "__stacksize"
/usr/include/gconv.h:176: warning: array `__data' assumed to have one element
回复 支持 反对

使用道具 举报

发表于 2005-5-3 09:32:05 | 显示全部楼层
楼主确信你编辑和编译的是同一个文件吗
回复 支持 反对

使用道具 举报

发表于 2005-5-3 10:34:13 | 显示全部楼层

请楼主再尝试一遍

从输出结果来看和简单的hello.c程序大相径庭!
我建议楼主还是专门建立一个文件夹,然后将
hello.c程序放进去编译。
另外该程序也可以这样写:
#include<stdio.h>
int main()
{
  printf("Hello,world!\n");
  return 0;
}
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-5-6 10:31:21 | 显示全部楼层
成功了,不过编译后执行hello,提示错误:
command not found!
在windows下象我那么写是可以的,为什么在linux下要int main,然后return 0呢?
回复 支持 反对

使用道具 举报

发表于 2005-5-6 10:44:09 | 显示全部楼层
./hello
Then it will be OK.
回复 支持 反对

使用道具 举报

发表于 2005-5-6 11:37:58 | 显示全部楼层
Post by erniu
在windows下象我那么写是可以的,为什么在linux下要int main,然后return 0呢?


标准C就是这么规定的。vc自己支持不标准的写法。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-5-6 14:14:02 | 显示全部楼层
以前在tc下也是这么写的,谭浩强的c语言书也是这么写的。看来要看看标准c了。
回复 支持 反对

使用道具 举报

发表于 2005-5-6 19:26:23 | 显示全部楼层
Post by erniu
以前在tc下也是这么写的,谭浩强的c语言书也是这么写的。看来要看看标准c了。

那些都是很古老的东东了.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表