C 错误:未定义对“_itoa”的引用
我正在尝试使用以下行将整数转换为字符以写入文件:
fputc(itoa(size, tempBuffer, 10), saveFile);
并且我收到此警告和消息:
警告:隐式声明'itoa'
未定义引用'_itoa'
我已经包含了 stdlib.h,并且正在编译:
gcc -Wall -pedantic -ansi
任何帮助将不胜感激,谢谢。
I'm trying to convert an integer to a character to write to a file, using this line:
fputc(itoa(size, tempBuffer, 10), saveFile);
and I receive this warning and message:
warning: implicit declaration of 'itoa'
undefined reference to '_itoa'
I've already included stdlib.h, and am compiling with:
gcc -Wall -pedantic -ansi
Any help would be appreciated, thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
itoa
不是标准的一部分。我怀疑-ansi
阻止您使用它,或者它根本不可用。我建议使用
sprintf()
如果您使用 c99 标准,则可以使用
snprintf()
这当然更安全。itoa
is not part of the standard. I suspect either-ansi
is preventing you from using it, or it's not available at all.I would suggest using
sprintf()
If you go with the c99 standard, you can use
snprintf()
which is of course safer.这里告诉你在编译阶段
itoa
是未知的:因此,如果您的系统上存在此函数,您将缺少声明它的头文件。然后,编译器假设它是一个接受不确定数量的参数并返回
int
的函数。此消息来自加载阶段
解释了加载程序在他所知道的任何库中都找不到这样的函数。
因此,您也许应该遵循 Brian 的建议,用标准函数替换
itoa
。This here tells you that during the compilation phase
itoa
is unknown:so if this function is present on your system you are missing a header file that declares it. The compiler then supposes that it is a function that takes an unspecific number of arguments and returns an
int
.This message from the loader phase
explains that also the loader doesn't find such a function in any of the libraries he knows of.
So you should perhaps follow Brian's advice to replace
itoa
by a standard function.