Difference between revisions of "Compiling on OpenWRT"

Wiki.TerraBase.info
Jump to navigation Jump to search
(Created page with "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/...")
 
m
Line 1: Line 1:
These are some notes, we'll see if it works and warrants a full article...
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
*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;
*A key resource are headers;
** To keep OpenWRT and Entware stuff separate, create the /opt directory: mkdir /opt
**To keep OpenWRT and Entware stuff separate, create the /opt directory: mkdir /opt
** Then it is safe to install / download this: wget -qO- <nowiki>http://bin.entware.net/armv7sf-k3.2/include/include.tar.gz</nowiki> | tar xvz -C /opt/include
**Then it is safe to install / download this: wget -qO- <nowiki>http://bin.entware.net/armv7sf-k3.2/include/include.tar.gz</nowiki> | 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
*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
**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: -I''WhatEverDirectory''
**Downloading the above Entware Header File, this command can be used to search a different directory, like /opt/include, first: -I''WhatEverDirectory''
* Items to install;
*Items to install;
** Make: https://man7.org/linux/man-pages/man1/make.1.html
**Make: https://man7.org/linux/man-pages/man1/make.1.html
*** opkg install gcc make
***opkg install gcc make
** Entware recommends installing the following: opkg install busybox ldd make gawk sed (a version of ldd and sed are included within the OpenWRT version of BusyBox)
**Entware recommends installing the following: opkg install busybox ldd make gawk sed (a version of ldd and sed are included within the OpenWRT version of BusyBox)
** Additional utilities are recommended
**Additional utilities are recommended
*** 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", but... (rpath is for run time (not compile time) libraries, https://en.wikipedia.org/wiki/Rpath)
**export LDFLAGS="-Wl,-rpath=/opt/lib -Wl,--dynamic-linker=/opt/lib/ld-linux.so.3 -L/opt/lib", but... (rpath is for run time (not compile time) libraries, https://en.wikipedia.org/wiki/Rpath)
*** needs to be adjusted for OpenWRT (/usr/lib) instead of DD-WRT (/opt/lib)
***needs to be adjusted for OpenWRT (/usr/lib) instead of DD-WRT (/opt/lib)
** This is needed too, but...: export CFLAGS="-O2 -pipe -march=armv7-a -mtune=cortex-a9 -fno-caller-saves -mfloat-abi=soft "
***LDLFLAGS = "-L/opt/include" is the same as: export LIBRARY_PATH=/opt/include (https://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html)
*** ...but add this to it: export CFLAGS="-O2 -pipe -march=armv7-a -mtune=cortex-a9 -fno-caller-saves -mfloat-abi=soft -I/opt/include"
****<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)
** CFLAGS = "-I/opt/include" is the same as: export CPATH=/opt/include (https://gcc.gnu.org/onlinedocs/cpp/Environment-Variables.html)
***LDLFLAGS = "-rpath=/opt/lib" is the same as: export LD_LIBRARY_PATH = "/opt/lib
** LDLFLAGS = "-L/opt/include" is the same as: export LIBRARY_PATH=/opt/include (https://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html)
****<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)
*** <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
**export CFLAGS="-O2 -pipe -march=armv7-a -mtune=cortex-a9 -fno-caller-saves -mfloat-abi=soft ", but...
** LDLFLAGS = "-rpath=/opt/lib" is the same as: export LD_LIBRARY_PATH = "/opt/lib LIBRARY_PATH, but not the same, below is a good explanation (from https://stackoverflow.com/questions/4250624/ld-library-path-vs-library-path);
***...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"
*** <code>LD_LIBRARY_PATH</code> is used by your program to search directories containing ''shared'' libraries after it has been successfully compiled and linked.
***CFLAGS = "-I/opt/include" is the same as: export CPATH=/opt/include (https://gcc.gnu.org/onlinedocs/cpp/Environment-Variables.html

Revision as of 15:07, 19 October 2020

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;
    • Make: https://man7.org/linux/man-pages/man1/make.1.html
      • opkg install gcc make
    • Entware recommends installing the following: opkg install busybox ldd make gawk sed (a version of ldd and sed are included within the OpenWRT version of BusyBox)
    • Additional utilities are recommended
      • Install the full version of BASH: opkg install bash
  • Environment variables to add;