[prog] undefined reference to itoa

Almut Behrens almut-behrens at gmx.net
Sun Dec 18 00:59:39 EST 2005


On Sat, Dec 17, 2005 at 02:36:12PM +0200, Asl?  wrote:
> hi everyone,
> i have quite an incomprehensible problem. I am writing some kind of an
> authentication application between servers and clients using socket APIs.
> This is the part of my code that drove me crazy:
> 
> char error_message[MAX_ERROR] ="Name not registered";
> 
>                             itoa(strlen(error_message),error_len,10);
> 
>  i compiled the file with gcc  (gcc file_s.c -o file_s) and got the message:
> 
> In function `main':
> : undefined reference to `itoa'
> collect2: ld returned 1 exit status
> 
> which seems to be a linker error. I was quite sure that "itoa" is in stdlib,
> and i include stdlib in my code.

Unfortunately, this (very handy) function is not ANSI C, even though
it's often found on other platforms/compilers, e.g. Microsoft.
IOW, it's simply not available in stdlib on Linux.

If you only need decimal (or hex) number base, I'd suggest to use
sprintf() instead -- that's at least highly portable.  Also see here
http://www.jb.man.ac.uk/~slowe/cpp/itoa.html for a related discussion.

Cheers,
Almut


More information about the Programming mailing list