How to cross-compile a program in raspberry pi with OpenWrt?

Hi all,

I have a 3rd party program that needs to be compiled in raspberry pi with openWRT.

Can I use "apt-get install" like in Ubuntu linux to install cross-compile? If not, what should I do next?

When I use "make CROSS-COMPILE=arm-none-linux-gnueabi-", some error is here:

make: arm-none-linux-gnueabi-gcc: No such file or directory

When I use "make", some error is here:

/usr/bin/ld: cannot find -lpthread
/usr/bin/ld: cannot find -ldl
/usr/bin/ld: cannot find -lrt
collect2: error: ld returned 1 exit status

Thank you.

Start here:

If you compile in the router itself for the same router, it wouldn't be cross-compile but just native compile.

But OpenWrt is not really made for compiling in the router itself. The router does not have the toolchain or the libraries.

Your best bet is to cross-compile in an external x86 Linux host.

3 Likes

Hi hnyman,

Thanks for your suggestion.
As your said, it’s native compile. If I try to cross-compile in an external x86 Linux host, can I do it in 5.10 Linux kernel? Because I found the kernel version is 5.4 of my raspberry openWRT.

Thanks.

Snapshots use newer kernels than stable.

The compilation host kernel version plays no role. Openwrt toolchain, imagebuilder and SDK all install/include the respectively correct kernel headers for OpenWrt.

But you need to be sure to use the OpenWrt compilation tools matching exactly the OpenWrt version that you are running. Easiest would be if you compile the whole firmware with that new program included.

1 Like

Thanks. In fact, this is what I want to consider.
Now I directly download the official openWRT image file, but my actual situation is that my Raspberry Pi is connected to other hardware which includes the mentioned software programs that need to be compiled. As you said, what is the way to compile the whole firmware? Is there any reference guide?

See the above link by @RuralRoots - It's how to setup the build environment to compile from source.

You will need to package yourself any software that isn't already available in the OpenWrt package repo. You can find out more about creating packages https://openwrt.org/docs/guide-developer/packages

Thank you. I will try. :clap: