It's assumed that the SDK has been downloaded and installed on the Ubuntu machine. If it hasn't been installed, please refer to http://wei48221.blogspot.tw/2017/05/linkit-smart-7688-7688-duo-using.html for instructions on how to download and install it.
Note, the method described below builds an executable file that can be executed directly by using the "./filename" command.
Step-1, Find the location of "mipsel-openwrt-linux-gcc"
sudo find -name mipsel-openwrt-linux-gcc
Note,
For an Ubuntu machine with "OpenWrt SDK for C/C++ for Linux" installed under the "SDK" folder, below is the location of the file "mipsel-openwrt-linux-gcc".
./SDK/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mipsel-openwrt-linux-gcc
For an Ubuntu machine with "C/C++ Toolchain for Linux" installed under the "OpenWrt-Toolchain-ramips-mt7688_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64" folder, below is the location of the file "mipsel-openwrt-linux-gcc".
./OpenWrt-Toolchain-ramips-mt7688_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mipsel-openwrt-linux-gcc
Judging from the experiment below, having the SDK installed on the Ubuntu machine is enough for cross compilation and there is no need to install the Toolchain.
Step-2, Prepare the helloworld.c file to be compiled
#include <stdio.h>
int main(int argc, char** argv)
{
printf("Hello, World!\n");
return 0;
}
Step-3, Use "mipsel-openwrt-linux-gcc" to compile
SDK/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mipsel-openwrt-linux-gcc helloworld.c -o helloworld
Check the result. There is a helloworld
Check the status "ls -l".
Step-4, Use WinSCP to copy helloworld from Ubuntu to LinkIt Smart 7688 Duo.
Use "chmod +x helloworld" to make the file executable.
Use "./helloworld" to run the program.
--------------------------------------------------------------------------------------------------------------------------
How to set STAGING_DIR and PATH
The section below is obtained from https://github.com/japaric/rust-on-openwrt
To verify that you got the right SDK, we'll compile a "Hello, world!" C program, and run it on the OpenWRT device.
When working with the OpenWRT SDK you'll need to set these two environment variables (STAGING_DIR & PATH), and be sure to keep them in your environment for the rest of this how-to.
# Make sure you are in the OpenWRT SDK folder
$ pwd
/home/japaric/openwrt
$ export STAGING_DIR="$PWD/staging_dir"
$ export PATH="$PWD/$(echo staging_dir/toolchain-*/bin):$PATH"
You should now be able to call the cross compiler, which should be in your
PATH
:$ mips-openwrt-linux-gcc -v
gcc version 4.8.3 (OpenWrt/Linaro GCC 4.8-2014.04 r42625)
--------------------------------------------------------------------------------------------------------------------------For my setup, below are the commands issued and the screenshot.
root@root-192.168.2.16:~$ cd SDK
root@root-192.168.2.16:~/SDK$ pwd
/home/root/SDK
root@root-192.168.2.16:~/SDK$ export STAGING_DIR="$PWD/staging_dir"
root@root-192.168.2.16:~/SDK$ export PATH="$PWD/$(echo staging_dir/toolchain-*/bin):$PATH"
root@root-192.168.2.16:~/SDK$ mipsel-openwrt-linux-gcc -v
In the commands above, "wei-hsiung" is replaced with "root" to shorten the line so that the command could be shown in one line.
To verify the STAGING_DIR and PATH have been set correctly
First, check to make sure that "helloworld.c" is in the working directory and there is no executable "helloworld" in the same directory.
Second, issue "mipsel-openwrt-linux-gcc helloworld.c -o helloworld". Then, check again the content of the same directory.
Indeed, there is now an executable "helloworld" in the same directory. And, there is no warning message about STAGING_DIR not defined.
Reference:
How to compile with the openwrt toolchain
http://wiki.wrtnode.com/index.php?title=How_to_compile_with_the_openwrt_toolchain
C Cross Compile for Linkit Smart 7688
https://www.slideshare.net/svrnuke/c-cross-compile-for-linkit-smart-7688
No comments:
Post a Comment