OpenWrt Forum Archive

Topic: C++ Experiences on LinkSys WRT54GL

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

I have OpenWRT RC4 on the new WRT54GL v4 router. I want to add customized C++ app onto the firmware (footprint size ~400KB)

I was able to compile all C++ src into obj files with a customized Makefile (using nmap sample) under the OpenWRT-SDK-Linux-i686-1's package dir that configures and calls another customized Makefile for my C++ app; but I get link errors.

I used mipsel-linux-uclibc-ar and mipsel-linux-uclibc-ranlib to create an archived library called "libofx.a" for easier linking and got the following errors:

/home/pbtran/LinkSys/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/mipsel-linux-uclibc-g++ -o ofxdb ofx_db.cc -fPIC -g -O3 -Wall -Wno-deprecated -Os -pipe -mips32 -mtune=mips32 -funit-at-a-time -I. -I./ -I/home/pbtran/LinkSys/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/include -I/home/pbtran/LinkSys/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/usr/include -nodefaultlibs -luClibc++ -lc -lm -lstdc++ -L. -L./ -L/home/pbtran/LinkSys/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/usr/lib -L/home/pbtran/LinkSys/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/lib -lofx
./libofx.a(_ofxdb.o):/home/pbtran/LinkSys/OpenWrt-SDK-Linux-i686-1/package/ofx/fx-3.0/_ofxdb.cc:140: undefined reference to `log2'
./libofx.a(_index.o):/home/pbtran/LinkSys/OpenWrt-SDK-Linux-i686-1/package/ofx/fx-3.0/_index.cc:427: undefined reference to `ceilf'
./libofx.a(_index.o):/home/pbtran/LinkSys/OpenWrt-SDK-Linux-i686-1/package/ofx/fx-3.0/_index.cc:427: undefined reference to `floorf'
./libofx.a(_query.o):/home/pbtran/LinkSys/OpenWrt-SDK-Linux-i686-1/package/ofx/fx-3.0/_query.cc:430: undefined reference to `ceilf'
./libofx.a(_query.o):/home/pbtran/LinkSys/OpenWrt-SDK-Linux-i686-1/package/ofx/fx-3.0/_query.cc:431: undefined reference to `ceilf'
collect2: ld returned 1 exit status
make: *** [ofxdb] Error 1


The funny thing is that I see the references using "strings" command (and this compiles and links fine on Linux RH ES 4 and on MacOS 10.4) :

[pbtran@linux fx-3.0]$ strings libofx.a | grep -i log2
log2
[pbtran@linux fx-3.0]$ strings libofx.a | grep -i ceilf
ceilf

We disabled some of the C99 math support to reduce the size of our images. I will add an extra library with those missing functions soon.

May I ask what's the timeframe to include C99 math library support for OpenWRT?

Thanks for all your help, ndb!!!

nbd wrote:

We disabled some of the C99 math support to reduce the size of our images. I will add an extra library with those missing functions soon.

Hi,

I was able to compile & link by juss commenting out the C99 math lib and get the ipk files. I think OpenWRT is the best open src extension for WRT54G/GL out there. I've experimented with HyperWRT + tofu and  DDWRT and both are not really well documented as OpenWRT is.

Keep up the good work ndb and the OpenWRT developers and contributors. You guys rock!!!

Cheers,
~Peter


pbtran wrote:

May I ask what's the timeframe to include C99 math library support for OpenWRT?

Thanks for all your help, ndb!!!

nbd wrote:

We disabled some of the C99 math support to reduce the size of our images. I will add an extra library with those missing functions soon.

nbd wrote:

We disabled some of the C99 math support to reduce the size of our images. I will add an extra library with those missing functions soon.

Hi,

I have a similar problem when compiling a customized version of cups:

imagetops.o: In function `main':
imagetops.c:(.text+0xf80): undefined reference to `ceilf'
imagetops.c:(.text+0xfc4): undefined reference to `ceilf'
../filter/.libs/libcupsimage.so: undefined reference to `cbrt'
collect2: ld returned 1 exit status
make[1]: *** [imagetops] Fehler 1
make: *** [all] Fehler 1

I tried to add DO_C99_MATH=y to toolchain_build_mipsel/uClibc-0.9.27/.config, and then running make in that directory, but it didn't help.

Any ideas how can I enable it?

Hi mangoo,

I actually substituted the src code on C99 lib functions with C/C++ operators.

e.g. For ceilf, you can return (float)((int) x + 1);

~Peter


mangoo wrote:

Hi,

I have a similar problem when compiling a customized version of cups:

imagetops.o: In function `main':
imagetops.c:(.text+0xf80): undefined reference to `ceilf'
imagetops.c:(.text+0xfc4): undefined reference to `ceilf'
../filter/.libs/libcupsimage.so: undefined reference to `cbrt'
collect2: ld returned 1 exit status
make[1]: *** [imagetops] Fehler 1
make: *** [all] Fehler 1

I tried to add DO_C99_MATH=y to toolchain_build_mipsel/uClibc-0.9.27/.config, and then running make in that directory, but it didn't help.

Any ideas how can I enable it?

For the ceilf definition, you can use the libnotimpl whic provides the ceilf function, do not forget to link agains this library, and to add the lnotimpl.a to your SDK if not present !

Adding (back) C99 compliant math functions is really easy to do yourself and takes about five minutes (not counting compile time for the toolchain).  Many more functions (like floorf and ceilf) are included in uClibc 0.9.19 and above so they are in the source distribution you download and compile for OpenWrt, but they are not included in the libm.a.  Incidentally, floorf and ceilf, each, add about 500 bytes to the math library.

To do it yourself, take a look at my HOW-TO: http://openwrt.pbwiki.com/Adding_Math_F … bc_mathlib (available from the Kamikaze HOW-TO list at http://openwrt.pbwiki.com/HowTos ).

What would be nice, is to have a section in make menuconfig that allows one to select which of the math functions they want.

The discussion might have continued from here.