Compile simple C program to run on OpenWrt


I've got a hopefully simple question. I've just ran through the "Hello World" example on the Wiki and successfully produced the .ipk which I transferred to my router, installed the package and ran it to produce "Hello, world!". All great!

But my question is, how do I compile the program directly so I can copy just the program and run it?

I believe I've found the correct GCC compiler, in my case I think it is in:


then used the command to build a program from the .c file:

arm-linux-gnueabihf-gcc -c -o helloworld.o ~/openwrt/code/helloworld/helloworld.c
arm-linux-gnueabihf-gcc -o helloworld helloworld.o

but when I copy the resulting helloworld to my router and try running it with:


I get:

-ash: ./helloworld: not found

I've checked and I think I have the correct permission:

-rwxr-xr-x 1 root root 7984 Aug 14 11:47 helloworld

I'm using a Pi for my development environment and a ASUS RT-AC66U B1 for the test environment.



1 Like

Do a
file helloworld
on your Pi, and also copy /bin/busybox from your router and run file on it. It should give comparable output

Work with the buildsystem, cross compiling involves setting a lot of parameters and environment variables (I'd venture that your previous attempt built against your host's libc and not the target libc (musl)).

1 Like

If you want the full command that is being run (not just the compiler), you can rebuild using the verbose option.

make -j1 V=s

then in the output, you'll be able to see the full command (compiler, LD_LIBRARY_PATH, etc). If you run that command manually, it will produce the same output as the make does.


This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.