<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Linux Daily &#187; Programming</title>
	<atom:link href="http://www.thelinuxdaily.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thelinuxdaily.com</link>
	<description>Tutorials, Guides, Tips, and Tricks from Everyday Experiences</description>
	<lastBuildDate>Thu, 02 Sep 2010 21:38:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Calculating /proc/cpuinfo BogoMIPS After Kernel Init</title>
		<link>http://www.thelinuxdaily.com/2010/06/calculating-proccpuinfo-bogomips-after-kernel-init/</link>
		<comments>http://www.thelinuxdaily.com/2010/06/calculating-proccpuinfo-bogomips-after-kernel-init/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 14:00:14 +0000</pubDate>
		<dc:creator>Derek@TheDailyLinux</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[bogomips]]></category>
		<category><![CDATA[calculate]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[Kernel]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[program]]></category>

		<guid isPermaLink="false">http://www.thelinuxdaily.com/?p=1894</guid>
		<description><![CDATA[Upon starting up your Linux kernel, a bogoMIPS calculation will be made and recorded into /proc/cpuinfo. This is a value that is not dynamically updated, so if you change the clock speed of the CPU, the bogoMIPS value contained in /proc/cpuinfo will not be updated. If all you&#8217;re interested in is a simple verification that [...]]]></description>
			<content:encoded><![CDATA[<p>Upon starting up your Linux kernel, a <a href="http://en.wikipedia.org/wiki/BogoMips">bogoMIPS</a> calculation will be made and recorded into /proc/cpuinfo.  This is a value that is not dynamically updated, so if you change the clock speed of the CPU, the bogoMIPS value contained in <a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?proc+5">/proc/cpuinfo</a> will not be updated.  If all you&#8217;re interested in is a simple verification that your CPU speed was changed, you could compile and run the following bogoMIPS calculation program both before and after the clock speed change.</p>
<p><a href="http://www.ibiblio.org/pub/linux/system/status/bogo-1.2.tar.gz">http://www.ibiblio.org/pub/linux/system/status/bogo-1.2.tar.gz</a></p>
<p>Simply call &#8216;make&#8217; to compile the program.  You may need to modify the Makefile in accordance to your needs (cross compiling, gcc flags, etc).  You may notice that the bogoMIPS value calculated by this program is not the same as the value calculated by the kernel.  That&#8217;s okay.  What matters here is that you can verify a change in CPU speed.  After all, &#8220;bogo&#8221; stands for &#8220;bogus&#8221; which simply means &#8220;fake&#8221;.</p>
<p>Source:<br />
<a href="http://tldp.org/HOWTO/BogoMips/bogo-faq.html">http://tldp.org/HOWTO/BogoMips/bogo-faq.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thelinuxdaily.com/2010/06/calculating-proccpuinfo-bogomips-after-kernel-init/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Yet Another Quick Serial Read c Program</title>
		<link>http://www.thelinuxdaily.com/2010/05/yet-another-quick-serial-read-c-program/</link>
		<comments>http://www.thelinuxdaily.com/2010/05/yet-another-quick-serial-read-c-program/#comments</comments>
		<pubDate>Thu, 13 May 2010 14:00:03 +0000</pubDate>
		<dc:creator>Derek@TheDailyLinux</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[proc]]></category>
		<category><![CDATA[program]]></category>
		<category><![CDATA[quick]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[serial]]></category>
		<category><![CDATA[usb]]></category>

		<guid isPermaLink="false">http://www.thelinuxdaily.com/?p=1765</guid>
		<description><![CDATA[Here&#8217;s yet another quick example of a serial capture c program that I came across while at work the other day. I just figured I would share&#8230; int main(int argc, char * argv[]){ while(1){ FILE *fp; fp = fopen(&#34;/proc/bus/usb/001/003&#34;, &#34;r&#34;); char buff[100]; while(fscanf(fp, &#34;%s&#34;, buff) != EOF){ printf(&#34;%s\n&#34;, buff); } fclose(fp); } return 0; }]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s yet another quick example of a serial capture c program that I came across while at work the other day.  I just figured I would share&#8230;</p>
<pre class="brush: cpp;">
int main(int argc, char * argv[]){
while(1){
FILE *fp;

fp = fopen(&quot;/proc/bus/usb/001/003&quot;, &quot;r&quot;);

char buff[100];
while(fscanf(fp, &quot;%s&quot;, buff) != EOF){
printf(&quot;%s\n&quot;, buff);
}
fclose(fp);
}
return 0;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.thelinuxdaily.com/2010/05/yet-another-quick-serial-read-c-program/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Grab Raw Keyboard Input from Event Device Node (/dev/input/event)</title>
		<link>http://www.thelinuxdaily.com/2010/05/grab-raw-keyboard-input-from-event-device-node-devinputevent/</link>
		<comments>http://www.thelinuxdaily.com/2010/05/grab-raw-keyboard-input-from-event-device-node-devinputevent/#comments</comments>
		<pubDate>Wed, 12 May 2010 14:00:18 +0000</pubDate>
		<dc:creator>Derek@TheDailyLinux</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[capture]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[device]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[grab]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[keyboard]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[node]]></category>
		<category><![CDATA[program]]></category>
		<category><![CDATA[raw]]></category>

		<guid isPermaLink="false">http://www.thelinuxdaily.com/?p=1793</guid>
		<description><![CDATA[The following is a quick c program that will capture raw keyboard data from the event device node such as /dev/input/event1. Simply compile and run with the specific device node as an argument. ie. ./keyboard_key_capture /dev/input/event1. #include &#60;stdio.h&#62; #include &#60;stdlib.h&#62; #include &#60;string.h&#62; #include &#60;unistd.h&#62; #include &#60;errno.h&#62; #include &#60;fcntl.h&#62; #include &#60;dirent.h&#62; #include &#60;linux/input.h&#62; #include &#60;sys/types.h&#62; #include [...]]]></description>
			<content:encoded><![CDATA[<p>The following is a quick c program that will capture raw keyboard data from the event device node such as /dev/input/event1.  Simply compile and run with the specific device node as an argument.  ie. <code>./keyboard_key_capture /dev/input/event1</code>.</p>
<pre class="brush: cpp;">
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#include &lt;unistd.h&gt;
#include &lt;errno.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;dirent.h&gt;
#include &lt;linux/input.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;sys/stat.h&gt;
#include &lt;sys/select.h&gt;
#include &lt;sys/time.h&gt;
#include &lt;termios.h&gt;
#include &lt;signal.h&gt;

void handler (int sig)
{
  printf (&quot;\nexiting...(%d)\n&quot;, sig);
  exit (0);
}

void perror_exit (char *error)
{
  perror (error);
  handler (9);
}

int main (int argc, char *argv[])
{
  struct input_event ev[64];
  int fd, rd, value, size = sizeof (struct input_event);
  char name[256] = &quot;Unknown&quot;;
  char *device = NULL;

  //Setup check
  if (argv[1] == NULL){
      printf(&quot;Please specify (on the command line) the path to the dev event interface device\n&quot;);
      exit (0);
    }

  if ((getuid ()) != 0)
    printf (&quot;You are not root! This may not work...\n&quot;);

  if (argc &gt; 1)
    device = argv[1];

  //Open Device
  if ((fd = open (device, O_RDONLY)) == -1)
    printf (&quot;%s is not a vaild device.\n&quot;, device);

  //Print Device Name
  ioctl (fd, EVIOCGNAME (sizeof (name)), name);
  printf (&quot;Reading From : %s (%s)\n&quot;, device, name);

  while (1){
      if ((rd = read (fd, ev, size * 64)) &lt; size)
          perror_exit (&quot;read()&quot;);      

      value = ev[0].value;

      if (value != ' ' &amp;&amp; ev[1].value == 1 &amp;&amp; ev[1].type == 1){ // Only read the key press event
	   printf (&quot;Code[%d]\n&quot;, (ev[1].code));
      }
  }

  return 0;
}
</pre>
<p>Here is an example output from running the above command.  Notice that <code>Code[]</code> is printed before the key that was pressed.</p>
<pre class="brush: bash;">
# ./keyb_key_cap_x86 /dev/input/by-id/usb-Dell_Dell_USB_Keyboard-event-kbd
Reading From : /dev/input/by-id/usb-Dell_Dell_USB_Keyboard-event-kbd (Dell Dell USB Keyboard)
Code[30]
aCode[48]
bCode[46]
cCode[32]
dCode[18]
eCode[33]
fCode[34]
gCode[35]
hCode[23]
iCode[36]
jCode[37]
kCode[38]
lCode[50]
mCode[49]
nCode[24]
oCode[25]
pCode[16]
qCode[19]
rCode[31]
sCode[20]
tCode[22]
uCode[47]
vCode[17]
wCode[45]
xCode[21]
yCode[44]
zCode[2]
1Code[3]
2Code[4]
3Code[5]
4Code[6]
5Code[7]
6Code[8]
7Code[9]
8Code[10]
9Code[11]
0
</pre>
<p>This is only an example program that I picked up from work.  I hope it will be of use to somebody out there so it can quickly help you get started with your project.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thelinuxdaily.com/2010/05/grab-raw-keyboard-input-from-event-device-node-devinputevent/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>A Great, Simple, Quick Serial Port Test Program for Linux</title>
		<link>http://www.thelinuxdaily.com/2010/04/a-great-simple-quick-serial-port-test-program-for-linux/</link>
		<comments>http://www.thelinuxdaily.com/2010/04/a-great-simple-quick-serial-port-test-program-for-linux/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 17:18:45 +0000</pubDate>
		<dc:creator>Derek@TheDailyLinux</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[fd]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[program]]></category>
		<category><![CDATA[rs232]]></category>
		<category><![CDATA[serial]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://www.thelinuxdaily.com/2010/04/a-great-simple-quick-serial-port-test-program-for-linux/</guid>
		<description><![CDATA[For any of you out there who would like to learn about serial programming or are in need of a simple serial program for testing, I would recommend checking out the one from &#8220;Captains Universe&#8221; here: http://www.captain.at/howto-simple-serial-port-test-example.php It&#8217;s easy to understand, modify, and compile and I think it&#8217;s a valuable tool in any programmers or [...]]]></description>
			<content:encoded><![CDATA[<p>For any of you out there who would like to learn about serial programming or are in need of a simple serial program for testing, I would recommend checking out the one from &#8220;Captains Universe&#8221; here:<br />
<a href="http://www.captain.at/howto-simple-serial-port-test-example.php">http://www.captain.at/howto-simple-serial-port-test-example.php</a></p>
<p>It&#8217;s easy to understand, modify, and compile and I think it&#8217;s a valuable tool in any programmers or embedded Linux users arsenal.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thelinuxdaily.com/2010/04/a-great-simple-quick-serial-port-test-program-for-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Time Tracking and Profiling Your Program with gprof</title>
		<link>http://www.thelinuxdaily.com/2010/04/time-tracking-and-profiling-your-program-with-gprof/</link>
		<comments>http://www.thelinuxdaily.com/2010/04/time-tracking-and-profiling-your-program-with-gprof/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 14:00:17 +0000</pubDate>
		<dc:creator>Derek@TheDailyLinux</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[optimize]]></category>
		<category><![CDATA[profile]]></category>
		<category><![CDATA[program]]></category>
		<category><![CDATA[troubleshoot]]></category>

		<guid isPermaLink="false">http://www.thelinuxdaily.com/?p=1738</guid>
		<description><![CDATA[Until today, I had only heard of the time program to track how much time a program took to execute entirely. This is useful to see if there are any optimizations that can be made to make the program run quicker, but it doesn&#8217;t help troubleshoot or debug a program very easily since it only [...]]]></description>
			<content:encoded><![CDATA[<p>Until today, I had only heard of the <a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?time">time</a> program to track how much time a program took to execute entirely.  This is useful to see if there are any optimizations that can be made to make the program run quicker, but it doesn&#8217;t help troubleshoot or debug a program very easily since it only tracks the entry and exit of the program being ran.  Another utility that allows you to track time in a more detailed manner is called <a href="http://www.manpagez.com/man/1/gprof/">gprof</a>.  Here&#8217;s a quote from the CS department of Utah School of Computing (<a href="http://www.cs.utah.edu/dept/old/texinfo/as/gprof.html">link</a>) explaining it in more detail:</p>
<blockquote><p>
Profiling allows you to learn where your program spent its time and which functions called which other functions while it was executing. This information can show you which pieces of your program are slower than you expected, and might be candidates for rewriting to make your program execute faster. It can also tell you which functions are being called more or less often than you expected. This may help you spot bugs that had otherwise been unnoticed.
</p></blockquote>
<p>Be sure to check out the man pages and other many guides out there that explain how to use it (no need for me to reinvent the wheel).  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.thelinuxdaily.com/2010/04/time-tracking-and-profiling-your-program-with-gprof/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert Small Array to Single Variable and Back Again</title>
		<link>http://www.thelinuxdaily.com/2010/04/convert-small-array-to-single-variable-and-back-again/</link>
		<comments>http://www.thelinuxdaily.com/2010/04/convert-small-array-to-single-variable-and-back-again/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 14:00:32 +0000</pubDate>
		<dc:creator>Derek@TheDailyLinux</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[int]]></category>
		<category><![CDATA[program]]></category>
		<category><![CDATA[variable]]></category>

		<guid isPermaLink="false">http://www.thelinuxdaily.com/?p=1583</guid>
		<description><![CDATA[Here is a method that will allow you to essentially merge elements of an array into a single variable and then back again in c. unsigned char mac_addr[6]; long long int x; x = mac_addr[0] &#60;&#60; 40; x &#124;= mac_addr[1] &#60;&#60; 32; x &#124;= mac_addr[2] &#60;&#60; 24; x &#124;= mac_addr[3] &#60;&#60; 16; x &#124;= mac_addr[4] [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a method that will allow you to essentially merge elements of an array into a single variable and then back again in c.</p>
<pre class="brush: cpp;">
unsigned char mac_addr[6];
long long int x;

x = mac_addr[0] &lt;&lt; 40;
x |= mac_addr[1] &lt;&lt; 32;
x |= mac_addr[2] &lt;&lt; 24;
x |= mac_addr[3] &lt;&lt; 16;
x |= mac_addr[4] &lt;&lt; 8;
x |= mac_addr[5];

mac_addr[0] = x &gt;&gt; 40;
mac_addr[1] = x &gt;&gt; 32;
mac_addr[2] = x &gt;&gt; 24;
mac_addr[3] = x &gt;&gt; 16;
mac_addr[4] = x &gt;&gt; 8;
mac_addr[5] = x;
</pre>
<p>You could probably take it a step further and throw it into a loop of sorts.  If you have another solution, feel free to share it in the comments below!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thelinuxdaily.com/2010/04/convert-small-array-to-single-variable-and-back-again/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Silence the rt73 Driver Message of MimeAssocReqAction()</title>
		<link>http://www.thelinuxdaily.com/2010/03/silence-the-rt73-driver-message-of-mimeassocreqaction/</link>
		<comments>http://www.thelinuxdaily.com/2010/03/silence-the-rt73-driver-message-of-mimeassocreqaction/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 15:00:39 +0000</pubDate>
		<dc:creator>Derek@TheDailyLinux</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[disable]]></category>
		<category><![CDATA[message]]></category>
		<category><![CDATA[remove]]></category>
		<category><![CDATA[rt73]]></category>
		<category><![CDATA[silence]]></category>
		<category><![CDATA[syslog]]></category>

		<guid isPermaLink="false">http://www.thelinuxdaily.com/?p=1547</guid>
		<description><![CDATA[If you utilize the rt2501usb chipset (rt73 driver) and are connect to your wireless LAN using WPA2 encryption, then you may have noticed a flurry of messages showing up in your syslog or dmesg output, filling up you logs: [ 1321.830000] MlmeAssocReqAction(): WPA2/WPA2PSK fill the ReqVarIEs with CipherTmp! [ 1323.980000] MlmeAssocReqAction(): WPA2/WPA2PSK fill the ReqVarIEs [...]]]></description>
			<content:encoded><![CDATA[<p>If you utilize the rt2501usb chipset (rt73 driver) and are connect to your wireless LAN using WPA2 encryption, then you may have noticed a flurry of messages showing up in your syslog or dmesg output, filling up you logs:</p>
<pre class="brush: plain;">
[ 1321.830000] MlmeAssocReqAction(): WPA2/WPA2PSK fill the ReqVarIEs with CipherTmp!
[ 1323.980000] MlmeAssocReqAction(): WPA2/WPA2PSK fill the ReqVarIEs with CipherTmp!
[ 1328.170000] MlmeAssocReqAction(): WPA2/WPA2PSK fill the ReqVarIEs with CipherTmp!
[ 1330.480000] MlmeAssocReqAction(): WPA2/WPA2PSK fill the ReqVarIEs with CipherTmp!
[ 1332.990000] MlmeAssocReqAction(): WPA2/WPA2PSK fill the ReqVarIEs with CipherTmp!
[ 1337.060000] MlmeAssocReqAction(): WPA2/WPA2PSK fill the ReqVarIEs with CipherTmp!
</pre>
<p>It seems to me that these are simply status/debugging messages and don&#8217;t serve much of a purpose other than fillings up the logs with information that&#8217;s not all that valuable to an end-user.  The connection still works, so it doesn&#8217;t seem out of line to simply comment out the offending lines in the source code.  If you don&#8217;t have the source code already, then you&#8217;ll need to goto RaLink and download them.  There are readme files that will help you compile from scratch.  When you have the source code, simply use grep to find the messages:</p>
<pre class="brush: bash;">grep -rn &quot;ReqVarIEs with CipherTmp&quot;</pre>
<p>You should find that the lines occur in the assoc.c file at line 348 and line 402.  Comment these lines out and recompile.  After this, your logs will be scotch-free of all those messages.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thelinuxdaily.com/2010/03/silence-the-rt73-driver-message-of-mimeassocreqaction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Cross Compile Example</title>
		<link>http://www.thelinuxdaily.com/2010/03/simple-cross-compile-example/</link>
		<comments>http://www.thelinuxdaily.com/2010/03/simple-cross-compile-example/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 03:32:28 +0000</pubDate>
		<dc:creator>Derek@TheDailyLinux</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[cross compile]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[toolchain]]></category>

		<guid isPermaLink="false">http://www.thelinuxdaily.com/?p=1446</guid>
		<description><![CDATA[The following is a very introductory guide to cross compiling a simple C++ program targeted towards an ARM platform. Development environments differ greatly, but for the most part, they all follow similar steps like outlined below. The very first step is to obtain a cross compile toolchain. CodeSourcery has a free, lite gcc toolchain available [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.thelinuxdaily.com/wp-content/uploads/2010/03/terminal_icon_orig.png" rel="lightbox[1446]"><img src="http://www.thelinuxdaily.com/wp-content/uploads/2010/03/terminal_icon_orig.png" alt="" title="terminal_icon_orig" width="128" height="128" class="left" /></a>The following is a very introductory guide to cross compiling a simple C++ program targeted towards an ARM platform.  Development environments differ greatly, but for the most part, they all follow similar steps like outlined below.  The very first step is to obtain a cross compile toolchain.  CodeSourcery has a free, lite gcc toolchain available for download (as mentioned in a <a href="http://www.thelinuxdaily.com/2010/02/codesourcery-com-a-place-to-get-cross-compile-toolchains-for-arm/">previous post</a>).  Once you download an appropriate toolchain for your target, you&#8217;ll need to extract it on your development host machine.  You&#8217;ll notice a directory structure similar to <em>opt/crosstool/gcc-4.0.1-glibc-2.3.5/arm-unknown-linux-gnu/bin/arm-unknown-linux-gnu-</em> which is what we&#8217;ll use here.<br />
<span id="more-1446"></span><br />
We must make a few other assumptions before beginning:  1.) The cross compiler will be located at <em>~/crosstool</em> (~ is equivalent to $HOME) and 2.) The program will be located at <em>~/main.cpp</em> which is also your current working directory (pwd).</p>
<p><strong>01.)</strong> Use the following greatest common divisor (gcd.cpp) file as an example if<br />
needed:</p>
<pre class="brush: cpp;">
#include
using namespace std;

int GCD(int a, int b)
{
   while( 1 )
   {
      a = a % b;
      if( a == 0 )
      return b;
      b = b % a;

      if( b == 0 )
      return a;
   }
}

int main()
{
   int x, y;

   cout &amp;lt;&amp;lt; &quot;This program allows calculating the GCD\n&quot;;
   cout &amp;lt;&amp;lt; &quot;Value 1: &quot;;
   cin &amp;gt;&amp;gt; x;
   cout &amp;lt;&amp;lt; &quot;Value 2: &quot;;
   cin &amp;gt;&amp;gt; y;

   cout &amp;lt;&amp;lt; &quot;\nThe Greatest Common Divisor of &quot;
   &amp;lt;&amp;lt; x &amp;lt;&amp;lt; &quot; and &quot; &amp;lt;&amp;lt; y &amp;lt;&amp;lt; &quot; is &quot; &amp;lt;&amp;lt; GCD(x, y) &amp;lt;&amp;lt; endl;

   return 0;
}
</pre>
<p><strong>02.)</strong> Use the cross compiling toolchain to compile the program:</p>
<pre class="brush: plain;">./crosstool/opt/crosstool/gcc-4.0.1-glibc-2.3.5/arm-unknown-linux-gnu/bin/arm-unknown-linux-gnu-g++ gcd.cpp -o gcd</pre>
<p><strong>03.)</strong> Copy the program to your target platform and then test by running it (alternatively, you could run it from an NFS server).  You will see:</p>
<pre class="brush: bash;">
ts7500:~# ./gcd
This program allows calculating the GCD
Value 1: 8
Value 2: 2

The Greatest Common Divisor of 8 and 2 is 2
ts7500:~#
</pre>
<p><strong>04.)</strong> Additionally, you can include the crosstools in your PATH for less typing:</p>
<pre class="brush: bash;">
PATH=$HOME/crosstool/opt/crosstool/gcc-4.0.1-glibc-2.3.5/arm-unknown-linux-gnu/bin/:$PATH
export PATH
arm-linux-uclibc-g++ gcd.cpp -o gcd
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.thelinuxdaily.com/2010/03/simple-cross-compile-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeSourcery.com:  A Place to Get Cross Compile Toolchains for ARM</title>
		<link>http://www.thelinuxdaily.com/2010/02/codesourcery-com-a-place-to-get-cross-compile-toolchains-for-arm/</link>
		<comments>http://www.thelinuxdaily.com/2010/02/codesourcery-com-a-place-to-get-cross-compile-toolchains-for-arm/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 17:07:49 +0000</pubDate>
		<dc:creator>Derek@TheDailyLinux</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[arm]]></category>
		<category><![CDATA[cross compile]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[toolchain]]></category>
		<category><![CDATA[WILT]]></category>

		<guid isPermaLink="false">http://www.derekhildreth.com/blog/?p=1064</guid>
		<description><![CDATA[This is something that I&#8217;m still coming to grips with, but today I learned that the cross compile toolchains that Technologic Systems provides for at least some of their products come from CodeSourcery.com. A quick blurb from their website: CodeSourcery, in partnership with ARM, Ltd., develops improvements to the GNU Toolchain for ARM processors and [...]]]></description>
			<content:encoded><![CDATA[<p>This is something that I&#8217;m still coming to grips with, but today I learned that the cross compile toolchains that Technologic Systems provides for at least some of their products come from CodeSourcery.com.  A quick blurb from their website:</p>
<blockquote><p>CodeSourcery, in partnership with ARM, Ltd., develops improvements to the GNU Toolchain for ARM processors and provides regular, validated releases of the GNU Toolchain. Sourcery G++ Lite Edition supports ARM, Thumb, and Thumb-2 compilation for all architectures in active use, including Version 7 of the ARM Architecture.</p></blockquote>
<p>For example, today I needed a newer version of the g++ cross compiler targeted towards EABI and glibc, so I took a look around the website at <a href="http://www.codesourcery.com/sgpp/lite/arm" target="_blank">http://www.codesourcery.com/sgpp/lite/arm</a> and found the release in the downloads section here: <a href="http://www.codesourcery.com/sgpp/lite/arm/portal/subscription?@template=lite" target="_blank"> http://www.codesourcery.com/sgpp/lite/arm/portal/subscription?@template=lite</a></p>
<p>A short term goal for myself is to figure out what goes into creating a cross compile environment.  I think this would be a valuable skill in the embedded Linux market.  For now, this was a shock to learn about how simple it really is to be able to simply download the toolchain and that there wasn&#8217;t any other trickery or knowledge required.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thelinuxdaily.com/2010/02/codesourcery-com-a-place-to-get-cross-compile-toolchains-for-arm/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>My First Makefile for Compiling GTK+ (Or Any) Apps</title>
		<link>http://www.thelinuxdaily.com/2010/01/my-first-makefile-for-compiling-gtk-or-any-apps/</link>
		<comments>http://www.thelinuxdaily.com/2010/01/my-first-makefile-for-compiling-gtk-or-any-apps/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 16:40:03 +0000</pubDate>
		<dc:creator>Derek@TheDailyLinux</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[compile]]></category>
		<category><![CDATA[first]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[make]]></category>
		<category><![CDATA[makefile]]></category>
		<category><![CDATA[newbie]]></category>
		<category><![CDATA[WILT]]></category>

		<guid isPermaLink="false">http://www.derekhildreth.com/blog/?p=829</guid>
		<description><![CDATA[A Makefile provides an easy, fast way to compile an application that requires more than just a simple gcc myprogram.c -o myprogram command. For example, to compile a GTK+ app, the common, basic compile command is gcc -g -Wall myguiapp.c -o myguiapp -export-dynamic `pkg-config &#8211;cflags &#8211;libs gtk+-2.0`. It&#8217;s not terrible, but it would be a [...]]]></description>
			<content:encoded><![CDATA[<p>A <a href="http://www.gnu.org/prep/standards/html_node/Makefile-Basics.html#Makefile-Basics" target="_blank">Makefile</a> provides an easy, fast way to compile an application that requires more than just a simple <em>gcc myprogram.c -o myprogram</em> command.  For example, to compile a GTK+ app, the common, basic compile command is <em>gcc -g -Wall myguiapp.c -o myguiapp -export-dynamic `pkg-config &#8211;cflags &#8211;libs gtk+-2.0`</em>.  It&#8217;s not terrible, but it would be a pain to have to retype that every time you need to recompile.  The alternative is to create a Makefile and type <em>make</em>.  This is my very first Makefile, and I believe it makes a great example:</p>
<pre class="brush: bash;">
NAME=myguiapp
CFLAGS=-g -Wall -o $(NAME)
GTKFLAGS=-export-dynamic `pkg-config --cflags --libs gtk+-2.0`
SRCS=main.c
CC=gcc

# top-level rule to create the program.
all: main

# compiling the source file.
main: $(SRCS)
 $(CC) $(CFLAGS) $(SRCS) $(GTKFLAGS)

# cleaning everything that can be automatically recreated with &quot;make&quot;.
clean:
 /bin/rm -f $(NAME)
</pre>
<p>As you can see, when <em>make</em> is called, it will compile the source with all my options including the program name.  When <em>make clean</em> is called, it will delete the compiled program.</p>
<p>One important thing to remember is that these Makefiles are very picky about spacing and tabs.  You MUST use a TAB at the beginning of commands and a TAB must not be at the beginning of blank lines.  The first error causes the commands not to run.   The second causes the &#8220;make&#8221; utility to complain that there is a &#8220;blank&#8221; command.</p>
<p>Obviously, this is an incredibly simple Makefile in comparison to a lot of them out there, but this is a good starting point.  You can customize the Makefile to match your compiling needs.  If you&#8217;d like to learn more, Google is your friend.  I can point you in a couple of good directions with these links:<br />
<a href="http://mrbook.org/tutorials/make/">http://mrbook.org/tutorials/make/</a><br />
<a href="http://www.cs.umd.edu/class/fall2002/cmsc214/Tutorial/makefile.html">http://www.cs.umd.edu/class/fall2002/cmsc214/Tutorial/makefile.html</a></p>
<p>Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thelinuxdaily.com/2010/01/my-first-makefile-for-compiling-gtk-or-any-apps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
