undefined reference error while using 'gets'

Jeff Johnston jjohnstn@redhat.com
Thu Nov 3 17:53:00 GMT 2011


On 11/03/2011 08:59 AM, Rohit Arul Raj wrote:
> Hi All,
>
> I am using newlib v1.18 built with 'powerpc-elf' v4.5.2. While using
> the 'gets' function call, i get the following error:
>
> powerpc-elf/4.5.2/../../../../powerpc-elf/lib\libc.a(lib_a-gets.o): In
> function `_gets_r':
> gets.c:(.text+0x30): undefined reference to `__sfp_lock_acquire'
> gets.c:(.text+0xa8): undefined reference to `__sfp_lock_release'
>
> Based on the documentation, it has been mentioned that 'gets' is
> obsolete and we need to use 'fgets'. But still i should not be getting
> any undefined reference errors.
>
> I took a look at the 'newlib\libc\stdio\gets.c' and i think we need to
> include "local.h" to get these definitions. Is that right?
>
> Let me know your suggestions.
>

Actually, Rohit, there was a lock issue that was fixed in January by 
Corinna so gets doesn't call __sfp_lock_xxxxx functions any more.

2011-01-28  Corinna Vinschen  <vinschen@redhat.com>

         * libc/stdio/fclose.c: Only use sfp lock to guard non-atomic
         changes of flags and fp lock.
         * libc/stdio/freopen.c: Ditto.
         * libc/stdio64/freopen64.c: Ditto.
         * libc/stdio/fgetc.c: Revert change from 2009-04-24, remove sfp 
locks
         which guard entire function to avoid potential deadlocks when using
         stdio functions in multiple thraeds.
         * libc/stdio/fgets.c: Ditto.
         * libc/stdio/fgetwc.c: Ditto.
         * libc/stdio/fgetws.c: Ditto.
         * libc/stdio/fread.c: Ditto.
         * libc/stdio/fseek.c: Ditto.
         * libc/stdio/getc.c: Ditto.
         * libc/stdio/getdelim.c: Ditto.
         * libc/stdio/gets.c: Ditto.
         * libc/stdio/vfscanf.c: Ditto.
         * libc/stdio/vfwscanf.c: Ditto.

I suggest you check out current newlib as it will have the most 
up-to-date fixes. Otherwise, you can attempt to patch your own code locally.

> Thanks,
> Rohit



More information about the Newlib mailing list