Disclaimer - There are others (at BUG and in the world) that know more about this subject than I do. I've just started to do some C coding for the BUG and wanted to share my experiences. Please share your thoughts and critique mine.
C programming for Linux devices just makes sense. It is, of course, much easier to use the BUG SDK and write Java code, but C is more powerful and allows you to do some things with the BUG that you can't do in Java. In this quick tutorial, I'll show how easy it is to write C code that runs on the BUG.
Step 1 - Set up your bitbake environment.
This is the hardest step. It can take a long time and be very frustrating if you're unfamiliar with some of the tricks. We have a detailed HowTo on our wiki here: http://bugcommunity.com/wiki/index.php/Kernel_and_Rootfs_Build_System -- You can do the Setup section (skipping QEMU) and the Build section up to java.
The end result of Step 1 is to build your own production image by running: bitbake bug-image-production (which is the hard part). Because platforms vary, you will inevitably encounter some problems. Luckily there are some troubleshooting tips on the bottom of the wiki page as well as on the "discussion" page. Another lucky thing is that bitbake will pick up where it left off if it fails. The last lucky thing is you can find help on our IRC channel (#buglabs @ freenode). The big unluckiness is this can take hours to complete. So, kick it off, check up on it occasionally to see if it's still going or if it failed.
Step 2 - Write some simple C code.
The more basic libraries are already on the BUG. A way to test if a library you depend on is there is to try to build it using bitbake, or to use dpkg-config from the bitbake devshell (remember to first cd into your build directory and run: source reinstate-build-env):
bitbake curl #it builds curl which tells me curl is available
bitbake -c devshell bug-image-production #opens up the dev shell
#in the dev shell do
dpkg-config --cflags --libs libcurl # should return the compiler and linker flags for curl
You may have to dig around to see how the environment calls the libraries, but it should be the same as on your workstation. All the packages are stored in one of the meta*/packages directories.
So, if a library you need is there, start coding. I code, compile, and test on my workstation before trying it out on the BUG. If you can't find a library you're missing, jump on IRC and ask around. Perhaps someone's already turned it into an ipkg for the BUG or has tips on how you can create your own. Update - finsprings shows how you can add packages from OpenEmbedded.
Step 3 - Compile your code for the BUG
This step is trivial once you've done all the above work. Basically, you get into a devshell
bitbake -c devshell [a package name like curl or bug-image-production]
and then compile using the arm compiler. Use $CC or $CPP (in your make file or at the command line) instead of gcc to make sure you're using the right compiler and toolchain -- something like...
$CC base.c -o base `pkg-config --cflags --libs [libname]`
In the following pastebin, I build the Hello World GTK example from the devshell. My comments are prefixed by a double slash (//) - http://pastebin.com/f4d6ba59c
That's it. I hope some people find this useful. Please leave comments and provide feedback if you have better methods or see how I can improve this quick tutorial.