arm-elf-ld then reports “… undefined reference to `sscanf’”.
I have tried everything in the book to fix the problem.
I have checked that the linker correctly picks up the reqired libc.a, and that sscanf.o is indeed in that library.
I realise after reading Bill Gatliff’s article that using newlib is not straightforward but this is so simple! If the linker can see the correct library and it has the correct object code in it how can it not resolve the reference?
Update: If I copy sscanf.o from the newlib build directory into my project and link it there, all is well; but that’s not a very elegant fix.
ntfreak:
…ld will by default only do one pass to resolve externals, so if your objects are after libc then you will get unresolved externals…
Aaaaaarrrrrgh! I’d forgotten that Spen. A final -lc on the ld command line fixed it properly. Thank you so much for helping me.
Edit 25 minutes later: But now I have problems if I try to use sprintf:
......newlib_build/arm-elf/newlib/libc/libc.a(sprintf.o): In function `_sprintf_r':
......newlib_sources/newlib/libc/stdio/sprintf.c:346: undefined reference to `_vfprintf_r'
ntfreak:
Why do you not just use gcc to link, you never have any problems with libs.
You can force ld to keep checking for externals by using, this is roughly what the gcc driver does.
–start-group archives --end-group
Cheers
Spen
Thanks Spen,
I agree, there’s really no reason not to use gcc - I’m just lazy and keep the makefiles from Jim Lynch’s tutorial which I know and love.
I sorted all my problems out in the end by remaking newlib.
For posterity: I used Tom Walsh’s build scripts which are ideal to get going with quickly. Unfortunately for me, the script to build newlib ran a patch on the makefile produced by configure and added a few “antibloat” flags to produce an integer only library. Very sensible for embedded stuff obviously but not for me who wants to use floating point and printf etc. during development.