Coding using C on the Onion Omega
Hi, I'm using the Onion Omega with USB as hdd.
I've installed gcc and libonionspi on the Onion Omega. I've made a simple main.c which #include <onion-spi.h> .. but I get errors when trying to compile it.. "fatal error: onion-spi.h: No such file or directory". I can't find that file anywhere. Am I missing a vital package or what's going on? :)
@huxflux Unfortunately the Omega doesn't really have the resources to actually run a compilation and build tool chain.
What you need to do is to set up cross compilation on a Linux system and do the building there and transfer the resultant executable to your Omega.
I do this regularly and have previously posted some basic instructions which can be found here: https://community.onion.io/topic/9/how-to-install-gcc/23
Hope that is of help to you
I hoped to dodge cross-compilation. I added an USB to fix this. This can't be about space. What's the deal?
I get what you're saying Kit Bishop. I might have to enter the world of cross-compiling if I want to code using C.
I've used a bit of time to look into this and have made some progress, I think. I found onion-spi.h and onion-debug.h on github.com/OnionIoT/. I'm now able to compile main.c with
gcc main.c -loniondebug -lonionspi. But the linker complains, and gives me this:
"/tmp/cciIexxg.o: In function `main':
main.c:(.text+0x2c): undefined reference to `spiParamInit'
collect2: error: ld returned 1 exit status"
I'm not sure how to fix this. I have libonionspi: /usr/lib/libonionspi.so .. not sure that file has anything to do with the error the linker gives me.
Oh, here's the very easy main.c for testing http://pastebin.com/gj8QT1k1
Made further progress. By hunting down onion-debug.c, onion-debug.h, onion-spi.c and onion-spi.h on github.com/OnionIoT/ I'm now able to compile and link my main.c with
gcc main.c onion-spi.c onion-debug.c
Looked some more into this. I'm not sure I understand the logic here.
When I execute
opkg install libonionspiit copies libonionspi.so to /usr/lib/. This is the dynamic library which the linker looks to when we run
gcc main.c -lonionspi. What I don't understand is, where's the header-file? They tell us to #include <onion-spi.h> (https://wiki.onion.io/Documentation/Libraries/SPI_Library_C).
As seen above I found those files on https://github.com/OnionIoT, but they're not updated (missing some functions).
Clearly I must be missing something vital here. I don't understand why I can't develop stuff on the Onion Omega itself. 8GB of hdd-space, 64MB RAM and I could add swap space if memory ever became a problem.
Still trying to avoid cross-compilation..
You could symlink your /usr/lib headers into whatever system header/compilation header libraries gcc on the device is expecting. Of course, you could also try to directly #include to the /usr/lib folder (NOT RECOMMENDED, i don't know why, but i'm pretty sure this is frowned upon by some neck-beard somewhere)
In any case, you could also be dealing with the fact that the OnionIOT headers are exported kernel headers, which may or may not work if they are stripped of something the kernel headers might have implicitly expected. But now we're descending into the madness of kernel vs exported headers, and I don't want to go down that path.
In any case, the cross-compilation toolchains aren't there because these embedded devices can't do it, so much as it ensures that if you can set up a cross-compilation toolchain that you can ensure OTHERS can develop just as you do for the same expected target. Embedded systems long ago (really since breaking the GHz mark) could handle on device compilation. However, it would take a while and development cycles are generally precious, therefore, most prefer to run it on a beefy machine.
That notwithstanding, I do think that there are more and more merits to on device compilation nowadays. My biggest wish is to run a linux system on a beefy but tiny AP like Onion Omega, and then connect to a virtual IDE hosted within it to actually develop from a pristine iPad or the like. This would make it so that I CAN have linux IDEs while using my sexy idevice.
Hope this helps. I'll look around to see what the latest is with on device development and see if I can't get you a more clear answer. Unless linux is built on the system itself, I don't have the faintest idea how to get development environments built without cross compilation though. Bitbake and openwrt are the best solutions to cross compilation, in that order, and even they eschew on device development.
Thanks for replying!
We already can compile on the Onion Omega using the
python-lightpackage. If you add some more space through USB, you can even install
gccon the Onion Omega. There are no problems whatsoever using Vim and compile C-code on this unit. The problem is when I want to use their libraries
libonioni2c. For some reason, they don't include the header-files when you install
The reason I want to code directly on the Onion Omega is because it's fast. I just want to write small programs that deal with the LEDS or read/write stuff to the GPIO's.
I could of course go without their libraries and go low-level myself. I might do it. Or maybe I should just go with Python. Or maybe go the cross-compilation route. We'll see :)
@huxflux When you install a library (like
libonioni2c) all that is installed is the compiled and linked code of the relevant library - it does not include any of the sources - in particular the
*.hfiles needed to reference the libraries. You need to ensure that the
*.hfiles are accessible when you build your program - either put them in the same directory as your source file or use the
-I<directory>option to point to the include files. If you do this, you should not need to separately and additionally compile the
*.cfiles for the library.
@huxflux Look at the cloud it just came out, it gives you the ability to compile c or c++ programs for your omega.
@Chris-McCaslin Not yet it doesn't as far as I can see. Though according to https://community.onion.io/topic/677/the-onion-roadmap it should be available early this month (May) :-)
@Kit Bishop I tried compiling using only the .h-files with
gcc main.c -loniondebug -lonionspi. The linker complains about not finding the reference to one of the functions. If I edit
libonionspi.soI can see the name of the function is there. So I'm at loss to what's going on here. It compiles, but doesn't link.
@huxflux Sorry not to be of any more help. :-( I haven't tried compiling on the Omega itself. My earlier comments were just possible suggestions
@huxflux Ahhhh, I see.
Is https://github.com/OnionIoT/spi-gpio-driver/blob/master/include/onion-spi.h what you are looking for then? I think if you download the files in this repo, and they are in somewhere like "/usr/include", you would then be able to satisfy the
@Lazar-Demin @Boken-Lin , can you all update https://wiki.onion.io/Documentation/Libraries/SPI_Library_C to include where to get and place the required spi files for this tutorial? Perhaps also ensure that the repo providing the spi driver for C code is definitely up to date?
@Theodore-Borromeo All of the articles in the Library Documentation section have been updated to point to the GitHub repo where the source code can be found.
All of the repos are definitely up to date, that's where the source code for our firmware comes from!
One more note:
Keep your eyes peeled in the next few weeks for the Cloud Compile feature to be released. You can avoid having GCC installed on your Omega and pulling code from all over the place. You'll be able to upload your source code, the cloud will cross-compile it for you, and then you will be able to choose which device you would like to push the compiled binary!
@Theodore-Borromeo Yes it fixes the dependency so I'm able to compile it, but not link it.
undefined referenceto one or more of the functions.
Cloud Compile sounds fancy schmancy :)
Also, do you have the onion spi library installed?
opkg update opkg install libonionspi
To install the library
@Lazar-Demin Yes, this is what I execute
gcc main.c -loniondebug -lonionspi
Here's the testfile for compiling http://pastebin.com/gj8QT1k1. I also have libonionspi.so and liboniondebug.so in /usr/lib/.
@huxflux What output do you get when you run that command?
Maybe try adding
-L /usr/libso it knows where to look for the dynamic libraries?