How to install gcc
After battling with this for quite some time, I finally have success with what I've been wanting to do :-)
Ended up being quite straightforward - I think I got bogged down in all the intricacies of building OpenWRT packages when all I wanted to do was build some basic C/C++ programs that would run on the Omega.
For the record, in case it is of help to others, this is what I ended up doing based largely on the info in:http://techfindings.one/archives/1487
For the record my host system for the compilation is a pretty standard KUbuntu-14.04 system running in a VM under VirtualBox
- Download the tool chain from https://s3-us-west-2.amazonaws.com/onion-cdn/community/openwrt/OpenWrt-Toolchain-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2
- Unpack it to some suitable directory (referred to below as <tc_dir>)
- Set up environment variables as follows (I put this in my ~/.profile file so it was always there):
- export STAGING_DIR
- Create your c program - e.g. test-prog.c
- Compile the program using (e.g.): mips-openwrt-linux-uclibc-gcc test-prog.c -o test-prog
- Transfer the output file (test-prog) to your Omega using you favourite tools.
- On the Omega in the directory you placed the file, run it by: ./test-prog - and there you are
I'm sure there will be other issues (e.g. using a makefile with multiple sources; access to libraries; building dynamic link libraries which I will want too), but these are all pretty standard development issues now that I have the code cross-compilation working.
@Boken-Lin Setup a Docker with the tool chain and cross compilers pre-configured. This way people can just docker run it from Ubuntu 14.04.
A VM for virtual box would be more general, similar to what the C.H.I.P. people are doing.
@John-Richardson In addition get one of the Arduino style libraries for Linux that the Intel Galileo people did to ease porting of Arduino Sketches.
Eventually the tool chain could plug into the Arduino IDE.
@John-Richardson Great ideas! We already have the docker image on our todo list. Just added the virtualbox VM to our todo as well.
Can you explain what you mean by Arduino style library for Linux?
@Boken-Lin Sure. Intel Edison and Galileo create a library (it's open sourced) that allows you to take simple Arduino programs and generate a native Linux executable. It easier the porting of existing projects.
The basic Arduino program setup is straightforward, the challenge is getting the right libraries and macro's to compiled out some AVR specific modifiers and intrinsics.
It may be a lot to ask, but it's popular to create Arduino IDE add-ins for different embedded devices. Recent work with Arduino 1.6.5 or later makes it easier to add in CPU specific compilers and tool chains, library headers, etc. They now have an SSH option to upload programs as well.
Maybe it's something the community could work on.
@John-Richardson This seems interesting, but could you elaborate on the generated executable?
Does the Arduino IDE generate an executable to run on the dev boards processor and flash an ATmega chip?
Or does it actually cross compile the Arduino sketch into an executable that can run natively on the dev board's processor?
@Lazar-Demin In the case of an Arduino/AVR it generates an executable using the gcc cross compiler, linker, ar, etc. It then generates a .hex file from the executable for firmware upload to the board using a tool such as avrdude, dfu, etc.
For a board which has an embedded linux, it generates a cross compiled executable for the board using the proper gcc, linker, ar, etc. It then has an SSH/RCP style method of copying the executable to the target system.
The key is recent changes to the Arduino IDE lets you customize the actions for every step. You can choose the headers and libraries to compile against for the target, you can choose the tools (cross compilers that run on the host and generate for the target), and the upload/copy method.
Intel Edison/Galileo is one example of such as setup targeting a board with embedded Linux from an Arduino IDE. It's made available as an add in as a "board package". Arduino 1.6.5 supports this newer way of supporting multiple embedded boards.
@John-Richardson wow, very cool of Atmel to build that in!
We'll be looking into this!
Anco van der Kolk
@Kit-Bishop thanks for your steps "how to do" to setup compiler was very helpful, I finaly have also a c program working, I had the same "file not found" problem, after following the wiki
mips-openwrt-linux-uclibc-gcc test-prog.c -o test-prog
I installed the toolchain and made a makefile to compile following code:
int main(int nArgc, char* pArgv)
printf("This is my first C app for Onion\n");
} // main
I get an error like this, I must be missing some initialisation #define !?
[simonjo@ASTR76L0 build]$ make -f Maketest.onion
rm -rf ../test.o test.onion
g++ -c -I /usr/onion/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/include -DONION -DOS="LINUX" -DLINUX -DDEBUG ../test.cpp -o ../test.o -I..
In file included from /usr/onion/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/include/stdio.h:36,
/usr/onion/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/include/bits/types.h:132:3: error: #error your machine is neither 32 bit or 64 bit ... it must be magical
In file included from /usr/onion/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/include/stdio.h:36,
/usr/onion/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/include/bits/types.h:137: error: â€˜__STD_TYPEâ€™ does not name a type
/usr/onion/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/include/bits/types.h:138: error: expected constructor, destructor, or type conversion before â€˜unsignedâ€™
/usr/onion/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/include/bits/types.h:139: error: expected constructor, destructor, or type conversion before â€˜unsignedâ€™
/usr/onion/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/include/bits/types.h:140: error: expected constructor, destructor, or type conversion before â€˜unsignedâ€™
Ok I managed to get past the problem in bits/types.h by adding '#define _MIPS_SZPTR 32'
But then I came to realize I was using the standard x86 compiler from my CentOS 6.5, not the one from the MIPS toolchain.
So I used the instructions to extend PATH and set STAGING_DIR, then use 'mips-openwrt-linux-uclibc-gcc test.cpp -o test.onion'
Now I get below error, I presume this is because my CentOS is 32bit and the toolchain contains 64bit executables... Do you have a 32bit version available ???
[simonjo@ASTR76L0 build]$ mips-openwrt-linux-uclibc-gcc test.cpp -o test.onion
/usr/onion/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-uclibc-gcc: line 82: /usr/onion/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-uclibc-gcc.bin: cannot execute binary file
/usr/onion/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-uclibc-gcc: line 82: /usr/onion/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-uclibc-gcc.bin: Success
@Johan-Simons A couple of points:
- From your first post, you should not need to have a #define _MIPS_SZPTR 32 in your code once you have sorted out the 32/64 bit issue. Using your source code exactly as posted using my 64 bit KUbuntu.14.04 set up, your code works as expected
- I have tried to look for a 32 bit version of the tool chain but can't find one. The link posted for the 64 bit tool chain was supplied by the Omega people. The best I have been able to find is from https://onion.io/downloads where it says:
- AR71xx Image Builder Pre-compiled OpenWrt build environment suitable for creating custom images without compiling everything from source. For x86_64 environment only!
- AR71xx SDK Pre-compiled OpenWRT toolchain for cross-compiling single userspace packages for a specific target without compiling the whole system from scratch. For x86_64 environment only!
- AR71xx Toolchain Uncompiled source for the AR71xx SDK. Useful if you need to compile the toolchain for 32-bit environments.
So I think your best bet will be to try to build the 32 bit toolchain yourself unless the guys at Omega can be prevailed upon to produce a precomiled 32 bit version
Thx for the response
Trying to compile a 32bit toolchain myself sounds kind of scary, I'm a Windows person, doing Linux is limited to using cross compilers...
I will check with some more Linux minded colleagues about this option and some help.
A second option might be easier, just get a 64bit version of Linux installed using netinstall, a good reason to start using an SSD.
Anyway, if the Onion crew can come up with a solution, that also would be appreciated very much.
A heads up... that last uncompiled toolchain you mentioned was a complete toolchain but also 64bit I guess as it gives me the same results
[root@ASTR76L0 bin]# ./mips-openwrt-linux-uclibc-gcc
./mips-openwrt-linux-uclibc-gcc: line 82: /usr/onion/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-uclibc-gcc.bin: cannot execute binary file
./mips-openwrt-linux-uclibc-gcc: line 82: /usr/onion/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-uclibc-gcc.bin: Success
@Johan-Simons So long as you have a 64 bit windows machine, easiest option is to probably install VirtualBox on your windows system (https://www.virtualbox.org/wiki/Downloads - get a 64 bit version).
Then do one of:
- Obtain a copy of the Linux system you want. I, and I believe several others, use 64 bit KUbuntu 14.04 - it is more than sufficient for what is needed - http://www.kubuntu.org/getkubuntu/ and install it on a VirtualBox image
- If you don't want the hassle of installing KUbuntu, prebuilt VirtualBox VM images are available from here: http://www.osboxes.org/kubuntu/ - though I don't know how they are configured in terms of memory and disk space setup. Just down load the one you want and open it in VirtualBox
Is there a reason that once we've added additional storage via overlay that we couldn't install a full gcc and associated build tools (make, autoconf, etc.) on the omega itself? I have gcc on there, but can't find a way to get make, etc. onto the little computer so I can compile other Linux software I want to port to the thing. Is there some hidden opkg of build tools I just don't know about?
@Johan-Simons If you can tell me the version of Linux you are using I can create the SDK for you.
@Justin-Sowers The Omega (or most OpenWRT devices for that matter) has very limited computational resources, so people don't generally compile anything directly on them, which is probably why you are unable to find packages that allow you to install build tools. However, things like
autoconfare just binaries that can you compiled from source. So if you want to compile it for the Omega, it's simply a matter of creating a
Makefilein your cross-compile environment and build an
opkgpackage out of them.
@Boken-Lin I read the post from @Justin-Sowers as meaning he wanted to be able to do the build actually on the Omega itself having made more space available via the overlay method. Though I'm sure you could give a more definitive response to this, it would seem to me that this would not be possible, not because of (disk) storage space but because of RAM limitations.