免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1724 | 回复: 3
打印 上一主题 下一主题

[C] __attribute__的编译问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-09-18 16:47 |只看该作者 |倒序浏览
//源文件test_attribute.c
extern void myprint(const char *format,...) __attribute__((format(printf,1,2)));

void test()
{
    myprint("i=%d\n",6);

    myprint("i=%s\n",6);

    myprint("i=%s\n","abc";

    myprint("%s,%d,%d\n",1,2);

}

int main(int argc,char **argv)
{
    test();
}

//编译test_attribute.c
arm-uclinux-gcc  -DDEBUG -Wall -Os -fstrict-aliasing -msoft-float -march=armv5 -                                             mtune=arm926ejs -mapcs-32  -fomit-frame-pointer       -c test_attribute.c  -o te                                             st_attribute.o
test_attribute.c: In function `test':
test_attribute.c:11: warning: format argument is not a pointer (arg 2)
test_attribute.c:15: warning: format argument is not a pointer (arg 2)
test_attribute.c:15: warning: too few arguments for format
test_attribute.c: In function `main':
test_attribute.c:22: warning: control reaches end of non-void function
arm-uclinux-gcc   -Wl,-elf2flt='-s 4000' -Os -msoft-float -march=armv5 -mtune=ar                                             m926ejs -mapcs-32  -fomit-frame-pointer    -o test_attribute   test_attribute.o
test_attribute.elf2flt(.text+0xc: In function `test':
: undefined reference to `myprint'
test_attribute.elf2flt(.text+0xd4): In function `test':
: undefined reference to `myprint'
test_attribute.elf2flt(.text+0xe0): In function `test':
: undefined reference to `myprint'
test_attribute.elf2flt(.text+0xf4): In function `test':
: undefined reference to `myprint'
collect2: ld returned 1 exit status
make: *** [test_attribute] Error 1

//问题
编译的时候为什么会提示:test_attribute.elf2flt(.text+0xc: In function `test':
: undefined reference to `myprint'了?
myprint()函数前面已经声明了啊?

论坛徽章:
0
2 [报告]
发表于 2008-09-18 16:51 |只看该作者
你的定义呢?你链接的时候要能找到。

论坛徽章:
0
3 [报告]
发表于 2008-09-24 10:49 |只看该作者

回复 #2 Fixend 的帖子

就是不知道怎么定义啊
void myprint(const char *format,...) __attribute__((format(printf,1,2)))
的参数个数不确定,怎么定义了?
谢谢

论坛徽章:
0
4 [报告]
发表于 2008-09-24 14:52 |只看该作者

  1. void myprint(const char *format,...)
  2. {
  3. /* Your Code */
  4. }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP