I have following problem - I've done baking pi course without any problems and then I 've decided to link this pure asm with some C. And I have done this and everything is working nice as far as I decided to use function sprintf to convert int to char*. Now when im trying to compile im enjoying following error
ctesty.c:(.text+0x20): undefined reference to 'sprintf'
make: *** [build/output.elf] Error 1
of course i have included stdio.h, i also tried to include this lib directly in makefile but without success.
You want to link with
libc.so. Try adding-lcin the link step in your makefiles.Update after Better Understanding of the Question
The Baking Pi examples build a
kernel.imgthat runs in place of the usual Linux kernel. This means that the C standard library is not available. You'll need to supply your ownsprintf()implementation, e.g.:uart_send_char()ee_printf()intosprintf()by makingbufa function parameterWhy a Userspace libc Wouldn't Work Without Source Modifications in any Kernel
Conceptually:
malloc,free), the file system (fopen,fcloseand all of stdio), environment variables (getenv), error handling facilities likesetjmplongjmpand more.mallocin a program running under an operating system?brk,sbrkandmmapunder Linux.brk,mmapetc wouldn't be the right interfaces to allocate memory.malloclike facilities, they won't be able to use the userspacemallocimplementations unmodified.fopen,getenvare not really that useful. Most kernel writers choose not to include them.In a more mechanical sense:
$(ARMGNU)-ld --no-undefined $(OBJECTS) -Map $(MAP) -o $(BUILD)output.elf -T $(LINKER). This doesn't linkbuild/output.elfwith any libc implementation so the linker wouldn't be able to find a symbol namedsprintf.gcc T.c -o T, gcc implicitly links in libc unless an option like-nostdlibis passed.But the conceptually important points are:
There are C standard library implementations targeting bare metal environments. See for example, newlib.