Compiling on OpenWRT
Jump to navigation
Jump to search
These are some notes, we'll see if it works and warrants a full article...
- Entware has better resources documentation for compiling on a router: https://github.com/Entware/Entware/wiki/Using-GCC-for-native-compilation
- A key resource are headers;
- To keep OpenWRT and Entware stuff separate, create the /opt directory: mkdir /opt
- Then it is safe to install / download this: wget -qO- http://bin.entware.net/armv7sf-k3.2/include/include.tar.gz | tar xvz -C /opt/include
- And from this source, it is easy to add the path when compiling: https://gcc.gnu.org/onlinedocs/cpp/Search-Path.html
- By default, gcc searches these directories first: /usr/include and /usr/lib/gcc/arm-openwrt-linux-muslgnueabi/7.4.0/include
- Downloading the above Entware Header File, this command can be used to search a different directory, like /opt/include, first: -IWhatEverDirectory
- Items to install;
- GCC:
- opkg install gcc
- Make: https://man7.org/linux/man-pages/man1/make.1.html
- opkg install make
- Entware recommends installing the following;
- opkg install busybox ldd make gawk sed (ldd and sed are not available as separate packages in OpenWRT, but both are included within the OpenWRT full version of BusyBox)
- Additional utilities are recommended
- Install the full version of BASH: opkg install bash
- GCC:
- Environment variables to add;
- export LDFLAGS="-Wl,-rpath=/usr/lib:/opt/lib -Wl,--dynamic-linker=/opt/lib/ld-linux.so.3 -L/opt/lib (the DD-WRT / Entware version: export LDFLAGS="-Wl,-rpath=/opt/lib -Wl,--dynamic-linker=/opt/lib/ld-linux.so.3 -L/opt/lib", needs to be modified for OpenWRT)
- -WI is a switch that allows for additional items to be added via the GNU LD (https://stackoverflow.com/questions/6562403/i-dont-understand-wl-rpath-wl) command
- -rpath in LDLFLAGS = "-rpath=/usr/lib:/opt/lib" is the same as executing this on the command line: export LD_LIBRARY_PATH = "/opt/lib
- rpath AND/OR
LD_LIBRARY_PATH
is a path used by an executable program to search directories containing shared libraries after the program has been compiled (from https://en.wikipedia.org/wiki/Rpath and https://stackoverflow.com/questions/4250624/ld-library-path-vs-library-path) - OpenWRT has its own equivalent path, which is /usr/lib, however there are some variations in files and sizes. Solution? Include both paths;
- -rpath=/usr/lib:/opt/lib (this will search OpenWRT's /usr/lib directory first, then DD-WRT / Entware's /opt/lib directory second)
- rpath AND/OR
- --dynamic-linker
- For DD-WRT / Entware it is located here: /opt/lib/ld-linux.so.3, which is a symbolic link to ld-2.27.so (and here too: /lib/gcc/arm-openwrt-linux-gnueabi/7.4.0)
- OpenWRT seems to have an equivalent GNU LD file located here: usr/lib/gcc/arm-openwrt-linux-muslgnueabi/7.4.0/ld-musl-armhf.so.1, but tragically, there is no environment path set.
- Note: LD is not the same as GNU LD (https://en.wikipedia.org/wiki/Linker_(computing)#GNU_linker)
- ELF Definition: https://en.wikipedia.org/wiki/Executable_and_Linkable_Format
- -L in LDLFLAGS = "-L/opt/lib" is the same as: export LIBRARY_PATH=/opt/lib (https://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html)
LIBRARY_PATH
is used by gcc before compilation to search directories containing static and shared libraries that need to be linked to your program (from https://stackoverflow.com/questions/4250624/ld-library-path-vs-library-path)-
- export CFLAGS="-O2 -pipe -march=armv7-a -mtune=cortex-a9 -fno-caller-saves -mfloat-abi=soft ", but...
- ...but because this is OpenWRT, not DD-WRT, add an item to the end of it: export CFLAGS="-O2 -pipe -march=armv7-a -mtune=cortex-a9 -fno-caller-saves -mfloat-abi=soft -I/opt/include"
- CFLAGS = "-I/opt/include" is the same as: export CPATH=/opt/include (https://gcc.gnu.org/onlinedocs/cpp/Environment-Variables.html
- export LDFLAGS="-Wl,-rpath=/usr/lib:/opt/lib -Wl,--dynamic-linker=/opt/lib/ld-linux.so.3 -L/opt/lib (the DD-WRT / Entware version: export LDFLAGS="-Wl,-rpath=/opt/lib -Wl,--dynamic-linker=/opt/lib/ld-linux.so.3 -L/opt/lib", needs to be modified for OpenWRT)
- ...as far as the Entware documentation for Compiling: https://github.com/Entware/Entware/wiki/Using-GCC-for-native-compilation
- Additional information for the ./configure --prefix /opt command, and what --prefix means: https://askubuntu.com/questions/891835/what-does-prefix-do-exactly-when-used-in-configure
- Although they offer a link and a command for downloading additional libraries to /opt/include, there doesn't appear to be any notation of where that is utilized. Just having it as a bunch of files in a directory is useless unless a compiler like GCC can make use of the files. It should be