打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
[Linux] undefined reference to `itoa'
本文转至http://blog.csdn.net/joeblackzqq/article/details/6934921
在linux写了个简单的C程序,里面用到了itoa,但是编译时提示“undefined reference to `itoa'”,本以为加上-lc就行了,可结果还是一样。上网发现,有人说这个函数在linux中是不存在的,一般用sprintf来代替。看下面代码及注释吧:
[cpp] view plaincopy
#include <stdio.h>
#include <stdlib.h>
//#include <unistd.h>
#include <string.h>
int num = 0;
char namebuf[100];
char prefix[] = "/tmp/tmp/p";
char* gentemp()
{
int length, pid;
pid = getpid();
strcpy(namebuf, prefix);
length = strlen(namebuf);
//itoa(pid, &namebuf[length], 10);      // Unix版本:itoa()在头文件<stdlib.h>中不存在
sprintf(namebuf+length, "%d", pid);     // 使用sprintf将整数转换成字符串
strcat(namebuf, ".");
length = strlen(namebuf);
printf("before do...while\n");
char command[1024] = {0};
do
{
//itoa(num++, &namebuf[length], 10);
sprintf(namebuf+length, "%d", num++);
sprintf(command, "touch %s", namebuf);  // 通过touch来创建文件
system(command);
printf("command = %s, namebuf[%d]=%d\n", command, num-1, num-1);
} while (num < 50 && access(namebuf, 0) != -1);  // access判断文件是否存在
printf("end of do...while\n");
return namebuf;
}
int main( void )
{
char *p = gentemp();
printf("%s\n", p);
return 0;
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
linux下出现undefined reference to `mysql_init' 的解决方法
example1.c:(.text+0x3d0): undefined reference to `cos'
gcc编译出现 undefined reference to ‘pthread_create‘ 的解决方法
undefined reference to 'pthread_create'问题解决
ld的-rpath与-rpath-link选项
交叉编译opencv
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服