Hello,

I spent a lot of time trying to cross compile a simple program for my nsul2 backfire target (10.03.1)

I have some experience in compiling and cross compiling but it is the 1st time that I am in a noway solution.


I'm working on debian squeeze latest stable
Linux eeebox 2.6.32-5-686 #1 SMP Sun May 6 04:01:19 UTC 2012 i686 GNU/Linux

I downloaded the following OpenWrtTool Chain
OpenWrt-Toolchain-ixp4xx-for-armeb_v5te-gcc-4.3.3+cs_uClibc-0.9.30.1_eabi.tar.bz2

Uncompressed into /usr/local/OpenWrt-SDK-ixp4xx-for-Linux-i686-gcc-4.3.3+cs_uClibc-0.9.30.1

Added the option to compile for nslu2 on my cross compile script (because I already cross compile other application for other targert withou a problem (not openwrt ). Changed the correct Var to be able to compile

export ARCH=armeb-openwrt-linux
export STAGING_DIR=/usr/local/OpenWrt-Toolchain-ixp4xx-for-armeb_v5te-gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/toolchain-armeb_v5te_gcc-4.3.3+cs_uClibc-0.9.30.1_eabi
export CC=$STAGING_DIR/usr/bin/$ARCH-gcc
export LD=$STAGING_DIR/usr/bin/$ARCH-ld
export RANLIB=$STAGING_DIR/usr/bin/$ARCH-ranlib
export CFLAGS="-I$STAGING_DIR/usr/include -I$STAGING_DIR/include"
export LDFLAGS="-L$STAGING_DIR/lib -L$STAGING_DIR/usr/lib"

Now I exec my script with . ./mycsript so var are correctly exported


root@eeebox:~# set | grep wrt
ARCH=armeb-openwrt-linux
CC=/usr/local/OpenWrt-Toolchain-ixp4xx-for-armeb_v5te-gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/toolchain-armeb_v5te_gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/usr/bin/armeb-openwrt-linux-gcc
LD=/usr/local/OpenWrt-Toolchain-ixp4xx-for-armeb_v5te-gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/toolchain-armeb_v5te_gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/usr/bin/armeb-openwrt-linux-ld
RANLIB=/usr/local/OpenWrt-Toolchain-ixp4xx-for-armeb_v5te-gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/toolchain-armeb_v5te_gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/usr/bin/armeb-openwrt-linux-ranlib
root@eeebox:~/hello# set | grep FLAGS
CFLAGS='-I/usr/local/OpenWrt-Toolchain-ixp4xx-for-armeb_v5te-gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/toolchain-armeb_v5te_gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/usr/include -I/usr/local/OpenWrt-Toolchain-ixp4xx-for-armeb_v5te-gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/toolchain-armeb_v5te_gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/include'
LDFLAGS='-L/usr/local/OpenWrt-Toolchain-ixp4xx-for-armeb_v5te-gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/toolchain-armeb_v5te_gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/lib -L/usr/local/OpenWrt-Toolchain-ixp4xx-for-armeb_v5te-gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/toolchain-armeb_v5te_gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/usr/lib'

Ok now go to my wonderfull program

root@eeebox:~/hello# cat hello.c
#include <stdio.h>

int main(void)
{
    printf("Hello World!\n");
    return 0;
}

Created Makefile

root@eeebox:~/hello# cat Makefile
OBJS= hello.o

all: hello

# ===== Compile
hello.o: hello.c
        $(CC) $(CFLAGS) -c hello.c

# ===== Link
hello: hello.o
        $(LD) $(LDFLAGS) $(LIBS) -o hello hello.o

clean:
        rm -f *.o hello

And the bad thing !!!

root@eeebox:~/hello# make
/usr/local/OpenWrt-Toolchain-ixp4xx-for-armeb_v5te-gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/toolchain-armeb_v5te_gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/usr/bin/armeb-openwrt-linux-gcc -I/usr/local/OpenWrt-Toolchain-ixp4xx-for-armeb_v5te-gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/toolchain-armeb_v5te_gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/usr/include -I/usr/local/OpenWrt-Toolchain-ixp4xx-for-armeb_v5te-gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/toolchain-armeb_v5te_gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/include -c hello.c
/usr/local/OpenWrt-Toolchain-ixp4xx-for-armeb_v5te-gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/toolchain-armeb_v5te_gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/usr/bin/armeb-openwrt-linux-ld -L/usr/local/OpenWrt-Toolchain-ixp4xx-for-armeb_v5te-gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/toolchain-armeb_v5te_gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/lib -L/usr/local/OpenWrt-Toolchain-ixp4xx-for-armeb_v5te-gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/toolchain-armeb_v5te_gcc-4.3.3+cs_uClibc-0.9.30.1_eabi/usr/lib  -o hello hello.o
armeb-openwrt-linux-uclibcgnueabi-ld.bin: warning: cannot find entry symbol _start; defaulting to 00008074
hello.o: In function `main':
hello.c:(.text+0xc): undefined reference to `puts'
make: *** [hello] Error 1

Look, the .o file was generated but I think I have a problem at the link stage.

root@eeebox:~/hello# ls -al
total 20
drwxr-xr-x  2 root root 4096 11 juin  15:46 .
drwxr-xr-x 23 root root 4096 11 juin  12:39 ..
-rw-r--r--  1 root root   85 11 juin  12:40 hello.c
-rw-r--r--  1 root root  996 11 juin  15:46 hello.o
-rw-r--r--  1 root root  190 11 juin  15:42 Makefile
root@eeebox:~/hello#

If someone has a idea ?