Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Intel edison cross compiling tricks on OS X

Cross compiling setup from OS X to Intel Edison poky linux

DISCLAIMER: this guide works for SDK version 1.7.2. If you have another version, verify file/URL names in the following.

Contents

Install toolchain

You need the edison cross-compile toolchain from Intel website (main page is here). Download it from there or proceed as follows:

$ curl -O http://downloadmirror.intel.com/25028/eng/edison-sdk-macosx-ww25.5-15.zip
$ unzip edison-sdk-macosx-ww25.5-15.zip
$ cd edison-sdk-macosx-ww25.5-15
$ sudo mkdir -p /opt/poky-edison/1.7.2/
$ sudo tar -xvf poky-edison-eglibc-i386-edison-image-core2-32-toolchain-1.7.2.tar -C /opt/poky-edison/1.7.2/

This sets up the x-compiling file structure. For actually using it, you have to issue source /opt/poky-edison/1.7.2/environment-setup-core2-32-poky-linux in your terminal, so that the appropriate env variables and paths get set.

Warning: I suspect that the script /opt/poky-edison/1.7.2/environment-setup-core2-32-poky-linux has at least one error at line 27, since all the LDFLAGS there reported are unsupported by the gcc cross-compiler. I have changed the line to export LDFLAGS="" and got no issues til now. Attached there is a patch for this (apply it with patch /opt/poky-edison/1.7.2/environment-setup-core2-32-poky-linux environment-setup.diff).

Warning 2: Another suspect: if you try to compile a C++ program, it will probably fail complaining about missing <iostream> (or any other C++ header). For fixing it, I replaced line 11 of environment-setup-core2-32-poky-linux with the following line (adding two include dirs):

export CXX="i586-poky-linux-g++  -m32 -march=core2 -mtune=core2 -msse3 -mfpmath=sse -mstackrealign -fno-omit-frame-pointer --sysroot=$SDKTARGETSYSROOT -I${SDKTARGETSYSROOT}/usr/include/c++/4.9.1 -I${SDKTARGETSYSROOT}/usr/include/c++/4.9.1/i586-poky-linux"

Missing flex library

Unfortunately version 1.7.2 of Intel toolkit is broken, and the ar command won't run complaining about the missing libfl.2.dylib. This is part of the Flex lexer. To fix this issue, download the flex library from sourceforge, then configure and compile it as follows:

$ bunzip flex-2.6.0.tar.bz2 && tar xvf flex-2.6.0.tar
$ cd flex-2.6.0
$ ./configure --prefix=/opt/poky-edison/1.7.2/sysroots/i386-pokysdk-darwin/usr/ CFLAGS='-arch i386'
$ make -j8
$ sudo make install

Note the CFLAGS switch: by default, on OS X gcc compiles for the 64-bit architecture, but the rest of the SDK commands are in i386 32-bit format. So you have to provide i586-poky-linux-ar an i386 shared library to link against, and thus that CFLAGS switch is mandatory.

From now on, just remember to:

$ source /opt/poky-edison/1.7.2/environment-setup-core2-32-poky-linux

before start compiling. Now x-compiling GCC suite of commands are in path as i586-poky-linux-[gcc|g++|ar|ld|nm|...].

LD config

In the following I am reporting a few examples of cross-compiling of useful libraries and commands. For a clean approach, I suggest to install every custom dynamic library on /usr/local/lib on your Edison. Note though, that /usr/local/lib is not in the list the system search paths for the dynamic object loader (ld), so the best you can do is probably:

$ echo "/usr/local/lib" >> /etc/ld.so.conf
$ ldconfig

Some hints

Luckily enough, networking is pretty well arranged by default on Edison. In order to simplify file transfer between your desktop and the Edison, I found the following setup very convenient.

  1. Use ssh config file and the USB-based ethernet connection. Wnen you plug in the Edison, it exposes an Ethernet connection with the address 192.168.2.15. Setup a static IP on your machine on the same subnet, install your public id_rsa.pub key on the Edison, and configure the .ssh/config file so that you only have to type ssh edison to connect via fast and stable USB-tunneled secure shell.
  2. Use sshfs: I have an empty $HOME/mnt mountpoint that I use as: sshfs edison:/home/root mnt. This way I have the whole content of my home folder on the Edison available on my machine as ~/mnt. Very handy.
  3. Now you can use $HOME/mnt/local as prefix path when you make install in your cross-compilations: after that, you'll find the binaries, libraries, and headers straight on the Edison on ~/local. Move to the Edison shell and cp -av ~/local/* /usr to install the products under /usr/.
  4. Even better, you can sshfs edison:/usr/local mnt, and then use as installation prefix $HOME/mnt in the recipes above. All the built products of your cross-compilation will be automatically put on the Edison in /usr/local/. Even more handy.
  5. Type umount mnt when you are done with it.

Note: these hints work on a Mac, provided that you have OSXFuse and sshfs installed. On Linux, they should probably work as fine, although the fuse SSH filesystem commands have some minor differences. If you are on Windows, I am not even spending time to explain why you should switch to another platform :p

Examples

Hereafter you find some guides for cross-compiling pretty useful and common packages, notably missing on OPKG. Before proceding, though, I suggest you to have a look at the hints section. In particular, installation commands are assuming that you have a working FuseFS sshfs command and that you mount the Edison /usr/local dir on $HOME/mnt. The install operations are then performed twice: first for installing the libs in your local (host) SDK tree, then for installing them on the Edison filesystem.

YAML library

I successfully compiled libyaml with the following commands:

$ curl -O http://pyyaml.org/download/libyaml/yaml-0.1.5.tar.gz
$ tar xzvf yaml-0.1.5.tar.gz && cd yaml-0.1.5
$ ./configure --host=i586-poky-linux --prefix=/your/absolute/path/to/usr
$ make -j8
$ sudo make install

PLEASE NOTE: These commands install the library and its headers under /your/absolute/path/to/usr/local/[lib|include], so that you can easily copy them on your Edison filesystem. If you rather need libYAML for x-compiling other software, you probably want to install the stuff on the local SDK, so that the configure line should read as follows:

$ ./configure --host=i586-poky-linux --prefix=$SDKTARGETSYSROOT/usr/local

And then remember to copy the shared library (if you are using it!) on the Edison. After copying, You probably want to check the LIBDIR stuff. I suggest you to have a look athe the GNU libtool page.

LibUV library

Some small changes for libUV:

$ curl -O http://dist.libuv.org/dist/v1.8.0/libuv-v1.8.0.tar.gz
$ tar xzvf libuv-v1.8.0.tar.gz && cd libuv-v1.8.0
# Perhaps you also need brew install libtoolize
$ LIBTOOLIZE=libtoolize sh ./autogen.sh
$ ./configure --host=i586-poky-linux --prefix=$SDKTARGETSYSROOT/usr/local
$ make -j8
$ sudo make install
# only if needed/possible:
$ sshfs edison:/usr/local $HOME/mnt
$ ./configure --host=i586-poky-linux --prefix=$HOME/mnt
$ make install

GSL - GNU Scientific Library

$ curl -O http://mirrors.muzzy.it/gnu/gsl/gsl-latest.tar.gz
$ tar xzvf gsl-latest.tar.gz && cd gsl-2.1
./configure --host=i586-poky-linux --prefix=$SDKTARGETSYSROOT/usr/local
make -j8
sudo make install
# only if needed/possible:
$ sshfs edison:/usr/local $HOME/mnt
$ ./configure --host=i586-poky-linux --prefix=$HOME/mnt
$ make install

Lua interpreter

For compiling base Lua interpreter and compiler (lua and luac) proceed as follows:

$ source /opt/poky-edison/1.7.2/environment-setup-core2-32-poky-linux
$ curl -O http://www.lua.org/ftp/lua-5.3.0.tar.gz
$ tar xzvf lua-5.3.0.tar.gz && cd lua-5.3.0
$ make -j8 CC=i586-poky-linux-gcc RANLIB=i586-poky-linux-ranlib AR="i586-poky-linux-ar rcu" linux
$ sudo make install INSTALL_TOP=$SDKTARGETSYSROOT/usr/local
# only if needed/possible:
$ sshfs edison:/usr/local $HOME/mnt
$ make install INSTALL_TOP=$HOME/mnt

LuaJIT interpreter

$ source /opt/poky-edison/1.7.2/environment-setup-core2-32-poky-linux
$ curl -O http://luajit.org/download/LuaJIT-2.0.4.tar.gz
$ tar xzvf LuaJIT-2.0.4.tar.gz && cd LuaJIT-2.0.4
$ make -j8 HOST_CC="gcc -m32" CROSS=$TARGET_PREFIX TARGET_SYS=Linux
$ sudo make install PREFIX=$SDKTARGETSYSROOT/usr/local
# only if needed/possible:
$ sshfs edison:/usr/local $HOME/mnt
$ make install PREFIX=$HOME/mnt

Watch out: when cross-building on OS X, the current LuaJIT makefile incorrectly installs the shared library files with the .dylib extension rather than the .so one. After installing the libraries, I suggest to move to /usr/local/lib on the Edison and do the followings:

$ cd /usr/local/lib
$ mv libluajit-5.1.2.0.4.dylib libluajit-5.1.2.0.4.so
$ ldconfig -n .
$ rm *.dylib

More OPKGs

Add the following package sources to /etc/opkg/base-feeds.conf for more sources:

src all     http://iotdk.intel.com/repos/2.0/iotdk/all
src x86 http://iotdk.intel.com/repos/2.0/iotdk/x86
src i586    http://iotdk.intel.com/repos/2.0/iotdk/i586

then opkg update.

Now you can for example install git: opkg install git

LuaJIT, luarocks, and Turbo

Turbo is a Lua framework for creating ReST services. Ir relies on LuaJIT rather than plain Lua (see above). In details, its requirements are:

  1. LuaJIT: cross compile it and install as above.
  2. git: opkg update && opkg install git
  3. coreutils: opkg install coreutils
  4. luarocks: It is much easier to build it natively on your Edison: downoald the tarball, ./configure --lua-suffix=jit --with-lua-include=/usr/include/luajit-2.0, then make && make install
  5. finally: luarocks install turbo

Credits

Started from https://gist.github.com/darylposnett/f11088a0ded82484a47e#file-intel-edison-cmdline-md

27c27
< export LDFLAGS="-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed"
---
> export LDFLAGS=""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.