c 调用同一目录下的其他文件中函数出错undefined reference to `hello

[复制链接]
查看11 | 回复4 | 2011-5-20 04:45:11 | 显示全部楼层 |阅读模式
第一个文件是hello.h,
内容为voidhello();
第二个文件是hello.c内容为
#include\"hello.h\"
voidhello()
{
printf(\"helloworld!\");
}
第三个文件是main.c,
内容为
#includestdio.h
#include\"hello.h\"

intmain()
{
hello();
}

编译出现错误undefinedreferenceto`hello\',求助
回复

使用道具 举报

千问 | 2011-5-20 04:45:11 | 显示全部楼层
用什么编译的,是建立的工程吗,还是只是单独的文件,没有建立工程,编译时要两个c文件一起编译。









<h4class=\"ask\">追问


没建立工程在linux下,用gcc编译的
回复

使用道具 举报

千问 | 2011-5-20 04:45:11 | 显示全部楼层
那就要在编译时,输入两个文件的名字了
gccmain.crhello.c
回复

使用道具 举报

千问 | 2011-5-20 04:45:11 | 显示全部楼层
/tmp/ccWBghFG.o:Infunction`main\':
main.c:(.text0x12):undefinedreferenceto`hello\'
collect2:ldreturned1exitstatus
回复

使用道具 举报

千问 | 2011-5-20 04:45:11 | 显示全部楼层
在linux下,用gcc编译的
回复

使用道具 举报

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

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行