-
Notifications
You must be signed in to change notification settings - Fork 151
Using gcc (native compilation)
gcc is included in arm* and x86* repositories. There is no gcc for mipsel repo. gcc package is considered beta in Openwrt, so it is beta in Entware. There are some limitations in gcc usage in Entware. It supports only dynamic linking. Static linking is not supported, there are no static libraries.
It is much more reliable to crosscompile binaries on a linux computer as it is described in the wiki - Compile packages from sources
There are some caveats in using gcc from Entware, that are described in the following sections.
install gcc with
opkg update
opkg install gcc
It is recommended to install busybox, make, ldd, gawk, sed packages before trying to use gcc
opkg install busybox ldd make gawk sed
Please consider installing patch
, diffutils
, coreutils-install
packages.
There are no *dev packages in Entware (as it comes from Openwrt). include files and static libs are not packed in ipk packages. There is a tar.gz archive of all include files from entware. If you use these include files, configure scripts may detect libraries that were not installed in Entware!
Here is a command to download and unpack headers form armv7
wget -qO- http://pkg.entware.net/binaries/armv7/include/include.tar.gz | tar xvz -C /opt/include
Substitute amv7 with (armv5,x86-32,x86-64) appropriate for your feed/architecture.
Binaries compiled in Entware must use rpath=/opt/lib
and a nonstandard dynamic linker. gcc package comes with /opt/bin/gcc_env.sh
script that helps to setup appropriate options for building binaries. For armv7 it is
#!/bin/sh
export LDFLAGS="-Wl,-rpath=/opt/lib -Wl,--dynamic-linker=/opt/lib/ld-linux.so.3 -L/opt/lib"
export CFLAGS="-O2 -pipe -march=armv7-a -mtune=cortex-a9 -fno-caller-saves -mfloat-abi=soft "
To setup environment variables for gcc execute
source /opt/bin/gcc_env.sh
or use the flags from /opt/bin/gcc_env.sh manually when building binaries. For example:
gcc $CFLAGS $LDFLAGS helloworld.c -o helloworld
Let's illustrate gcc usage to build screen binary. screen depends on libncurses, so install this libarary before building screen (opkg install libncurses
).
Suppose we have unpacked screen sources in the current directory.
First run configure script
./configure --prefix=/opt
It is important to use --prefix=/opt
in configuring binaries.
Second: run make
make
After make finishes - you can find screen binary in the current directory. You can check what shared object it uses:
ldd ./screen
libncurses.so.6 => /opt/lib/libncurses.so.6 (0x76eaa000)
libcrypt.so.1 => /opt/lib/libcrypt.so.1 (0x76e72000)
libgcc_s.so.1 => /opt/lib/libgcc_s.so.1 (0x76e5c000)
libc.so.6 => /opt/lib/libc.so.6 (0x76d21000)
/opt/lib/ld-linux.so.3 (0x76ef9000)
It is - ok. It uses shared objects from /opt/lib and /opt/lib/ld-linux.so.3 dynamic-linker. You can run and test screen
./screen
Third: You can install it
make install