OpenWrt Forum Archive

Topic: Cross-Compile for OpenWRT

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

Hello! I'm having big problems with compiling a simple program for my OpenWRT device.

Can someone please help me to set-up the compiling environment and tell me what do I have to run to successfully compile a program.
I don't need to compile a package, just a simple binary program, that I need for a serial port communication.

1.
I have TP-Link WR741ND v4.22 with ATTITUDE ADJUSTMENT (12.09-rc1, r34185).

I installed openwrt-ar71xx-generic-tl-wr741nd-v1-squashfs-sysupgrade.bin from here
http://downloads.openwrt.org/attitude_a … x/generic/

I obtained

OpenWrt-Toolchain-ar71xx-for-mips_r2-gcc-4.6-linaro_uClibc-0.9.33.2.tar.bz2

from the same link above.
For compiling I use debian.

2.
I don't know if I'm doing right, but tell me...
Where do I need to put my c_source_file.c?
And then I have to run

mips-openwrt-linux-uclibc-gcc

from toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin (downloaded toolchain above).

Am I doing right?

I did like this for kamikaze and everything worked well. But now on new router and ATTITUDE ADJUSTMENT I can't get things working.


Help, please, I'm not really a Linux programer, but i need this program to compile

(Last edited by pcpostar on 6 Apr 2013, 18:54)

I get error:

mips-openwrt-linux-uclibc-gcc.bin: warning: environment variable 'STAGING_DIR' not defined
test_for_compiling.c:3:20: fatal error: iostream: No such file or directory
compilation terminated.

Ok, i found a sollution how to simple cross-compile a program for openwrt...

You need source.c of your program
You need appropriate toolchain for the version of openwrt you are using.

Then you have to execute

export STAGING_DIR=/home/jordan/wr741nd/OpenWrt-Toolchain-ar71xx-for-mips_r2-gcc-4.6-linaro_uClibc-0.9.33.2

...or where you have your toolchain

Then you compile your source.c program with:

/home/jordan/wr741nd/OpenWrt-Toolchain-ar71xx-for-mips_r2-gcc-4.6-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-gcc source.c -o output_file_name

Feel free to ask for any details.
Hope it helps.

I also try to found a sollution how to simple cross-compile a program for openwrt.

do you need an openwrt package or just binary for openwrt?

(Last edited by pcpostar on 16 Apr 2013, 11:44)

... and you fixed it by following pcpostar's suggestion above???

I followed pcpostar's instructions, but when I do that, I either get a Segmentation Fault, or I get "cannot execute binary file".  I know the code works because if I compile it on ubuntu, it runs (it's just a simple printf statement).

The results I get depend upon where I point STAGING_DIR.  I have tried two different ways:

export STAGING_DIR = ~/openwrt/attitude_adjustment/staging_dir/toolchain_mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2
and
export STAGING_DIR = ~/OpenWRT-SDK/staging_dir/toolchain_mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2

Does anyone know how to diagnose either of these two problems?

The discussion might have continued from here.