Cross compile for Edison
Affiliate Disclosure: Some links on this blog are affiliate links, meaning I earn a commission at no extra cost to you. I only recommend products and services I trust and use myself.

Cross compile for Edison

Since I had a couple requests on how to cross-compile C/C++ programs for the Edison, I figured a quick post wouldn’t hurt. Note that I am using Ubuntu 14.04 (64-bit) for this example.

Download “SDK – Cross Compile Tools” from https://software.intel.com/en-us/iot/hardware/edison/downloads.

Unzip and run the installer. Note that the name of the files may change depending on the version of the SDK and your operating system.

unzip edison-sdk-linux64-ww25.5-15.zip
sh poky-edison-glibc-x86_64-edison-image-core2-32-toolchain-1.7.2.sh

Accept all defaults and let the SDK install.

Create a test program with nano hello.cpp (or your editor of choice) and enter:

#include <iostream>

int main()
{
    std::cout << "Hello, world!\n";
    return 0;
}

Set up the necessary environment variables and compiler with:

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

Cross-compile the example program with:

$CXX hello.cpp -o hello

Note that we’re using $CXX to refer to the g++ cross-compiler. Run echo $CXX to see what’s really going on. Now that we’ve compiled, transfer the executable over to the Edison. I used SCP:

scp hello root@192.168.2.15:/home/root

Log in to your Edison (serial terminal, SSH, etc.) and run it!

./hello

The information in this post came from this GitHub gist. Go there to see a more in-depth explanation, how to use gcc as well as g++, and set up the cross compile SDK on OSX and Windows.

4 thoughts on “Cross Compiling on Linux for the Edison

  1. lalit shandilya on April 26, 2017 at 10:59 am Reply

    i have done the same . but my code is not running continuously . code stops as soon as i closed the terminal window .can you please help me out about this .

    1. ShawnHymel on April 26, 2017 at 2:21 pm Reply

      If you’re run a program through an SSH terminal, then that program is associated with that session, meaning it will stop running when you close the terminal (quitting the session). If you need the program to run on boot or in the background, you’ll need to create a service in systemd: https://shawnhymel.com/792/run-a-script-on-edison-boot/.

  2. Lukasz on June 21, 2017 at 8:00 pm Reply

    Hi, thanks for the tutorial :). Just a little note- you wrote “$CXX hello.c -o hello” instead of “$CXX hello.cpp -o hello”

    1. ShawnHymel on June 25, 2017 at 6:01 pm Reply

      Fixed, thanks!

Leave a Comment

Your email address will not be published. Marked fields are required.