OpenWrt Forum Archive

Topic: Need help compiling printf

The content of this topic has been archived on 2 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

OK, I admit I'm pretty clueless when it comes to the nitty-gritty of compiling things.  Anything more complicated than ./configure, make, make install and I'm lost.

So here's my problem:
I'd like to make printf into a package - I've read PolarWolf's howto's and understand about a third of it due to my lack of experience doing this sort of thing.
I've found what appear to be a couple of nice, standalone implementations of printf that are optimised for embedded systems here:
http://mes.sourceforge.jp/h8/printf.html
and here:
http://www.menie.org/georges/embedded/

I've downloaded both files and can't compile either of them.
Here's some of the errors I'm seeing:

mipsel-linux-gcc -Wall -o printf printf-stdarg.c
/opt/brcm/hndtools-mipsel-linux/bin/../lib/gcc-lib/mipsel-linux/3.2.3/../../../../mipsel-linux/lib/crt1.o: In function `__start':
/opt/brcm/hndtools-mipsel-linux/bin/../lib/gcc-lib/mipsel-linux/3.2.3/../../../../mipsel-linux/lib/crt1.o(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status

and

mipsel-linux-gcc -Wall -o printf printf-20020909.c
printf-20020909.c:1: parse error before '.' token
In file included from /opt/brcm/hndtools-mipsel-linux/mipsel-linux/sys-include/bits/types.h:142,
                 from /opt/brcm/hndtools-mipsel-linux/mipsel-linux/sys-include/ctype.h:27,
                 from printf-20020909.c:2:
/opt/brcm/hndtools-mipsel-linux/mipsel-linux/sys-include/bits/pthreadtypes.h:48: parse error before "size_t"
/opt/brcm/hndtools-mipsel-linux/mipsel-linux/sys-include/bits/pthreadtypes.h:51: parse error before "__stacksize"
printf-20020909.c: In function `outstring':
printf-20020909.c:29: warning: implicit declaration of function `memcpy'
printf-20020909.c: In function `input_number':
printf-20020909.c:50: warning: implicit declaration of function `read_string'
printf-20020909.c:58: warning: implicit declaration of function `atodec'
printf-20020909.c:59: warning: implicit declaration of function `atohex'
printf-20020909.c: In function `hex':
printf-20020909.c:109: warning: unused variable `c'
printf-20020909.c: In function `vprintf':
printf-20020909.c:141: warning: implicit declaration of function `strlen'

These seem like fairly basic errors - maybe I don't have my linkers working correctly, but I'd appreciate some advice here...

In case you're wondering, I'd like to make printf a package so that it doesn't have to be compiled into busybox, and because Shorewall depends on it.

EDIT: OK, I realise now that the compilers I've been using are the broadcom-linksys ones and they probably don't work with OpenWRT.  Is this correct?

just curious, why not use busybox one ?

Good question. smile

Using the busybox printf would involve customising OpenWRT, and I want a Shorewall package that works with the standard OpenWRT.  I suppose I could create a new busybox with just printf in it, but that might be rather large for just one small app.  I suppose I could also request that future versions of standard OpenWRT come with printf compiled into busybox by default.  But my philosophy is that the read-only part of OpenWRT should have even less stuff in it than it currently has - small as it is right now, and that more should be customisable and loadable as packages.

I am struggling with this issue too, whether the read only part should have more or less ? I believe it would use the limited space of the flash more efficiently this way as I believe squashfs has a better compression ratio than jffs2.

fyi - awk can be used as a quick and dirty printf

echo | awk '{printf("%xn",42)}'

The discussion might have continued from here.