User Tools

Site Tools


openwrt_coding

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
openwrt_coding [2009/06/11 03:43]
eric
openwrt_coding [2013/05/21 16:12] (current)
eric
Line 3: Line 3:
 //Written by Eric Bishop <eric[AT]gargoyle-router.com>// //Written by Eric Bishop <eric[AT]gargoyle-router.com>//
  
-Part I: A Simple Program In C added 8/23/2007+[[openwrt_coding#Part I: A Simple Program In C -- 8/23/2007]]
  
-Part II: C++ and the Standard Template Library (STL) added 10/10/2007+[[openwrt_coding#Part II: C++ and the Standard Template Library (STL) -- 10/10/2007]]
  
-Part III: Building and Using the Kamikaze SDK added 12/9/2007+[[openwrt_coding#Part III: Building and Using the Kamikaze SDK -- 12/9/2007]]
  
 =====Tutorial Moved To New Location -- 7/26/2008===== =====Tutorial Moved To New Location -- 7/26/2008=====
  
-I haven't updated this document in a while so be aware that some of the information here may be a bit out of date. I wrote this document almost a year ago now, but it still contains useful information about programming in C/C++ for OpenWrt. I recently released Gargoyle, a new web interface for OpenWrt, and I've moved this tutorial onto the official Gargoyle website. My old, website (which was kind of pathetic) is now obsolete, and has been taken down. I apologize for any inconvenience this may cause.+I haven't updated this document in a while so be aware that some of the information here may be a bit out of date. I wrote this document almost a year ago now, but it still contains useful information about programming in C/C++ for OpenWrt.  I recently released Gargoyle, a new web interface for OpenWrt, and I've moved this tutorial onto the official Gargoyle website. My old, website (which was kind of pathetic) is now obsolete, and has been taken down. I apologize for any inconvenience this may cause.
  
  
-This tutorial now makes use of external stylesheets to fit in with the Gargoyle website theme. I realize this may make it more difficult to download and easily reference on your local computer, so I will continue to make the old version of this tutorial available. This version can be found here.+This tutorial now makes use of external stylesheets to fit in with the Gargoyle website theme. I realize this may make it more difficult to download and easily reference on your local computer, so I will continue to make the old version of this tutorial available. This version can be found [[http://gargoyle-router.com/old-openwrt-coding.html|here]].
  
  
Line 22: Line 22:
  
  
-The code for the examples in this tutorial can be downloaded from here. The example from the first part of the tutorial is in the **openwrt-programming-examples/c** directory and the example for the White Russian portion of the second part is in the **openwrt-programming-examples/c++** directory. The modified Kamikaze SDK Makefile referred to in part III is also included in this zip file.+The code for the examples in this tutorial can be downloaded from [[http://www.gargoyle-router.com/openwrt-programming-examples.tar.gz|here.]] The example from the first part of the tutorial is in the **openwrt-programming-examples/c** directory and the example for the White Russian portion of the second part is in the **openwrt-programming-examples/c++** directory. The modified Kamikaze SDK Makefile referred to in part III is also included in this zip file.
  
 =====Part I: A Simple Program in C -- 8/23/2007===== =====Part I: A Simple Program in C -- 8/23/2007=====
Line 51: Line 51:
  
 helloworld: helloworld.o helloworld: helloworld.o
-     $(CC) $(LDFLAGS) helloworld.o -o helloworld helloworld.o: +     $(CC) $(LDFLAGS) helloworld.o -o helloworld 
-     helloworld.c $(CC) $(CFLAGS) -c helloworld.c + 
 +helloworld.o: helloworld.c  
 +     $(CC) $(CFLAGS) -c helloworld.c 
  
 # remove object files and executable when user executes "make clean" # remove object files and executable when user executes "make clean"
Line 286: Line 288:
 </shell>  </shell> 
  
-Now, ssh into the router. We just copied the package to root's home directory so we are finally ready to install our program. In root's home directory, (where we end up immediately after connecting to the router via ssh) type "ipkg install helloworld_1_mipsel.ipk" and the ipkg system will do the rest.+Now, ssh into the router. We just copied the package to root's home directory so we are finally ready to install our program. In root's home directory, (where we end up immediately after connecting to the router via ssh) type "ipkg install helloworld_1_mipsel.ipk" [NOTE: on OpenWrt 8.09 and later you need to run opkg install helloworld_1_mipsel.ipk, as ipkg has been replaced with a new, improved utility called opkg] and the ipkg system will do the rest.
  
 <shell> <shell>
Line 704: Line 706:
 Once again, please do **not** contact me about any issues you might have with your own programs.  If,however, you think there is an error in one of my examples or that I have omitted a critical detail, please contact me and I will try to resolve the issue as soon as possible. Once again, please do **not** contact me about any issues you might have with your own programs.  If,however, you think there is an error in one of my examples or that I have omitted a critical detail, please contact me and I will try to resolve the issue as soon as possible.
  
-=====PART III: Building and Using the Kamikaze SDK=====+=====PART III: Building and Using the Kamikaze SDK -- 12/9/2007=====
  
 The OpenWrt SDK for Kamikaze is available only for 64 bit processors. If you're one of us mere mortals who posesses only one of those antique 32 bit processors, you have a problem. You can sometimes get away with using the //White Russian// SDK if you only need your program to run on the MIPS architecture, but the new architectures supported only by Kamikaze require you to use a //Kamikaze// SDK. The solution is to compile the SDK yourself. This is actually fairly simple, provided you have a couple of gigabytes of disk space and an hour or two to spare.  The OpenWrt SDK for Kamikaze is available only for 64 bit processors. If you're one of us mere mortals who posesses only one of those antique 32 bit processors, you have a problem. You can sometimes get away with using the //White Russian// SDK if you only need your program to run on the MIPS architecture, but the new architectures supported only by Kamikaze require you to use a //Kamikaze// SDK. The solution is to compile the SDK yourself. This is actually fairly simple, provided you have a couple of gigabytes of disk space and an hour or two to spare. 
Line 870: Line 872:
 </shell> </shell>
  
 +
 +
 +That's all there is to compiling the SDK The SDK tar.bz2 file is now in the bin subdirectory. You can install it just as I describe above for the White Russian SDK that can be downloaded in its compiled form.
 +
 +However, if you are working with Kamikaze 7.09 (the latest as of this writing) or before, you're likely to have trouble compiling packages with your newly compiled SDK. There's a bug in the Makefile in the root build directory. A fix has been added to the svn repository, but is not in any release yet. A description of the problem, (now patched) can be found [[https://dev.openwrt.org/ticket/2508|here]]. To quickly fix this defect, extract the SDK directory and then edit the Makefile in the extracted root SDK directory. Open the file with your favorite editor and replace this code:
 +
 +**Excerpt from ~/kamikaze-sdk/Makefile (Broken):**
 +<code>
 +world: FORCE
 + $(MAKE) package/compile
 + -( \
 + cd package; \
 + find . -maxdepth 2 -name Config.in | \
 + sed -e 's,/Config.in,,g' | \
 + xargs -n1 $(MAKE) compile -C; \
 + )
 +
 +</code>
 +
 +With this, fixed, code:
 +
 +**Excerpt from ~/kamikaze-sdk/Makefile (Fixed):**
 +<code>
 +world: FORCE
 + $(MAKE) package/compile
 + -( \
 + cd package; \
 + for configfile in `find . -maxdepth 2 -name Config.in` ; do \
 + $(MAKE) compile -C `dirname $$configfile` ; \
 + done \
 + )
 +</code>
 +
 +You should now be able to compile your code just as you did with the //White Russian// SDK.
 +
 +I toyed with the idea of not reiterating, for a third time, that I only wish to be contacted if you find a problem with this tutorial, but given the number of people who have ignored my first two pleas, I decided better of it. I would also like to say that if you do need to contact me, it would be best to compose your message in English as opposed to l33t speak. I do not in any way mean to disparage those of you for whom English is not your first language by this statement, but merely those who have sent me messages containing more numeric and puctuation characters than alphabetic ones. Finally, some of you have also seen fit to ask for my help in exchange for money. Admittedly, I am not entirely opposed to this idea. However, if you really are interested in hiring me, please offer me a figure with at least three digits in it. Thank you.
 +
 +
 +This tutorial is provided under the [[http://creativecommons.org/licenses/by/3.0/us/|Creative Commons License, version 3.0.]]
openwrt_coding.1244691801.txt.gz · Last modified: 2009/06/11 03:43 by eric