GCC问题

系统安装、升级讨论
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
回复
gundamfj
帖子: 80
注册时间: 2010-10-09 17:18

GCC问题

#1

帖子 gundamfj » 2011-02-21 21:34

我按照这里的说明学习怎么用GCChttp://wiki.ubuntu.org.cn/index.php?tit ... iant=zh-cn

我按照编译多个源文件那个小节的说明做,最后出现了这个错误,我能够看懂错误提示,但是觉得这个错误很莫名其妙。。。。

错误如下:
root@jack-Aspire-4740:/home/jack/scripts# gcc -Wall hello.c hello_fn.c -o hello
hello.c: In function ‘hello’:
hello.c:3: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
hello.c:6: error: expected ‘{’ at end of input
hello_fn.c: In function ‘hello’:
hello_fn.c:4: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
hello_fn.c:6: error: expected ‘{’ at end of input

代码
hello.c

代码: 全选

#include "hello.h"
int main(void)
{
    hello ("world");
    return 0;
}
hello_fn.c

代码: 全选

#include <stdio.h>
#include "hello.h"
 
void hello (const char * name)
{
    printf ("Hello, %s!\n", name);
}
hello.h

代码: 全选

void hello (const char * name);


不知道怎么改,来求助= =
上次由 gundamfj 在 2011-02-22 12:30,总共编辑 1 次。
forestchen
帖子: 41
注册时间: 2008-05-11 11:10

Re: GCC问题

#2

帖子 forestchen » 2011-02-22 11:24

看这个编译错误,因该是代码有语法错误.如果可以,你可以贴出来让大家看看.
头像
farta
帖子: 443
注册时间: 2009-02-24 2:48

Re: GCC问题

#3

帖子 farta » 2011-02-22 22:47

MinGW(gcc在Windows下的移植版本)编译运行没遇到任何问题= =
gundamfj
帖子: 80
注册时间: 2010-10-09 17:18

Re: GCC问题

#4

帖子 gundamfj » 2011-02-23 18:42

farta 写了:MinGW(gcc在Windows下的移植版本)编译运行没遇到任何问题= =
所以才说这个错误很莫名其妙啊= =
头像
racnil
帖子: 288
注册时间: 2008-08-28 8:12
联系:

Re: GCC问题

#5

帖子 racnil » 2011-02-23 23:26

按照LZ写的代码做没有出现编译错误~~
SLAX and Xorg(without any Window Managers)
It's fun!
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
联系:

Re: GCC问题

#6

帖子 BigSnake.NET » 2011-02-24 1:20

把代码粘贴上来,这里的代码没问题,可能你机器上写的那个用了中文标点了
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
头像
racnil
帖子: 288
注册时间: 2008-08-28 8:12
联系:

Re: GCC问题

#7

帖子 racnil » 2011-02-24 17:15

也有可能是在哪个头文件里面或者是哪一行里面多加了一个分号
SLAX and Xorg(without any Window Managers)
It's fun!
头像
懒蜗牛Gentoo
论坛版主
帖子: 7353
注册时间: 2007-03-02 17:36
系统: Linux Mint

Re: GCC问题

#8

帖子 懒蜗牛Gentoo » 2011-02-24 17:19

在hello.h文件的最后加上一个空行看看
虽然世上没有完美的东西,但这并不影响我们追求完美,因为只有偏执狂才TMD能成功。
10.04新手入门——笨兔兔讲述自己的故事
回复