当前位置: 技术问答>linux和unix
编译__attribute__的问题
来源: 互联网 发布时间:2016-04-14
本文导语: //源文件test_attribute.c extern void myprint(const char *format,...) __attribute__((format(printf,1,2))); void test() { myprint("i=%dn",6); myprint("i=%sn",6); myprint("i=%sn","abc"; myprint("%s,%d,%dn",1,2); } int main(int argc,char *...
//源文件test_attribute.c
extern void myprint(const char *format,...) __attribute__((format(printf,1,2)));
void test()
{
myprint("i=%dn",6);
myprint("i=%sn",6);
myprint("i=%sn","abc";
myprint("%s,%d,%dn",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()函数前面已经声明了啊?
extern void myprint(const char *format,...) __attribute__((format(printf,1,2)));
void test()
{
myprint("i=%dn",6);
myprint("i=%sn",6);
myprint("i=%sn","abc";
myprint("%s,%d,%dn",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()函数前面已经声明了啊?
|
简单的你可以这样试下:
#include
//...
void myprintf (const char *format,...)
{
char printf_buf[1024];
va_list args;
int printed;
va_start(args, format);
printed = vsprintf(printf_buf, format, args);
va_end(args);
puts(printf_buf);
return;
}
// ...