Compiling on OpenWRT: Difference between revisions

mNo edit summary
mNo edit summary
Line 18: Line 18:
***Install the full version of BASH: opkg install bash
***Install the full version of BASH: opkg install bash
*Environment variables to add;
*Environment variables to add;
**export LDFLAGS="-Wl,-rpath=/opt/lib -Wl,--dynamic-linker=/opt/lib/ld-linux.so.3 -L/opt/lib"
**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)
***needs to be adjusted for OpenWRT
***-WI is a switch that allows for additional items to be added via the GNU [https://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_node/ld_3.html LD] (https://stackoverflow.com/questions/6562403/i-dont-understand-wl-rpath-wl) command
****OpenWRT -rpath equivalent is /usr/lib instead of DD-WRT's /opt/lib
***-rpath in LDLFLAGS = "-rpath=/usr/lib:/opt/lib" is the same as executing this on the command line: export LD_LIBRARY_PATH = "/opt/lib
****Path for /opt/include:
****rpath AND/OR <code>LD_LIBRARY_PATH</code> 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)
***-WI is a switch that allows for additional items to be added via [https://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_node/ld_3.html LD] (https://stackoverflow.com/questions/6562403/i-dont-understand-wl-rpath-wl)
****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)
***--dynamic-linker
***--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)
****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)
Line 31: Line 32:
****<code>LIBRARY_PATH</code> 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)
****<code>LIBRARY_PATH</code> 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)
****
****
***-rpath in LDLFLAGS = "-rpath=/opt/lib" is the same as: export LD_LIBRARY_PATH = "/opt/lib (rpath is for run time (not compile time) libraries, https://en.wikipedia.org/wiki/Rpath)
*****
****<code>LD_LIBRARY_PATH</code> is used by your program to search directories containing ''shared'' libraries after it has been successfully compiled and linked (from 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)
**export CFLAGS="-O2 -pipe -march=armv7-a -mtune=cortex-a9 -fno-caller-saves -mfloat-abi=soft ", but...
**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"
***...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"