<?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>Talk Computer &#187; eclipse</title>
	<atom:link href="http://www.talkcomputer.net/tag/eclipse/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.talkcomputer.net</link>
	<description>Tutorials, reviews, information, eveything for your technology needs!</description>
	<lastBuildDate>Thu, 02 Jul 2009 21:38:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Compiling for embedded processors (part 1)</title>
		<link>http://www.talkcomputer.net/2009/05/compiling-for-embedded-processors-part-1/</link>
		<comments>http://www.talkcomputer.net/2009/05/compiling-for-embedded-processors-part-1/#comments</comments>
		<pubDate>Wed, 27 May 2009 02:00:23 +0000</pubDate>
		<dc:creator>Cedric</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[compilers]]></category>
		<category><![CDATA[compiling]]></category>
		<category><![CDATA[development environment]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[linux distribution]]></category>
		<category><![CDATA[processor]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tarballs]]></category>
		<category><![CDATA[toolchain]]></category>

		<guid isPermaLink="false">http://www.talkcomputer.net/?p=35</guid>
		<description><![CDATA[In my current job, I came across some issues compiling for the Embedded ARM TS-7800. Because of certain library requirements and other limitations, compiling from the embedded device was not possible (although, in some cases it might). The only way to get around this issue is cross-compiling. Cross-compiling is compiling for a different architecture than [...]]]></description>
			<content:encoded><![CDATA[<p>In my current job, I came across some issues compiling for the <em>Embedded ARM TS-7800</em>. Because of certain library requirements and other limitations, compiling from the embedded device was not possible (although, in some cases it might). The only way to get around this issue is cross-compiling.</p>
<p>Cross-compiling is compiling for a different architecture than the one you are currently working on. If it&#8217;s your first time doing that kind of work, it can rapidly become frustrating since there is no &#8220;silver bullet&#8221; method. In this post, I will try to explain a method that should work for most embedded device provided that the manufacturer has a <em>toolchain</em> readily available.</p>
<p><strong>What you will need:</strong></p>
<ul>
<li>A computer with a Linux distribution (I used Fedora 7 [it's old but it worked] )</li>
<li>A compiler and the necessary libraries</li>
<li>The <em>toolchain</em> for the processor</li>
<li>Not necessary but will make you  life easier: a development environment (such as Eclipse)</li>
</ul>
<p>Let&#8217;s take a look at the 4 items previously listed. First, the Linux distribution; it&#8217;s not 100% required but it will make your life a lot easier since most <em>toolchains</em> (patience, we&#8217;ll get to what it is soon) are compiled for Linux.</p>
<p>The compiler that is most often used is GCC, a great compiler, free (<em>free as in speech</em> and <em>free as in beer</em>) and readily available of all (or almost) Linux distributions. You can get the Tarballs off their website at http://gcc.gnu.org/ or just use the package manager in you environment. I would suggest installing the required libraries for the code you are compiling at this point if it&#8217;s not already done.</p>
<p><em>Toolchains</em>, what are they? <em>Toolchains</em> are simply a set of compilers and libraries build to run on a certain architecture and compile for another. You will usually be able to get them from the manufacturer&#8217;s website or from the community. You will most likely find them packaged in Tarballs.</p>
<p>Finally, the development environment is useful because it let&#8217;s you consolidate and organize your code into neat folders and let&#8217;s you easily manage build options. With some addons, Eclipse will even let you sync a project directly from a SVN!</p>
<p><strong>Architecture, what&#8217;s that?</strong></p>
<p>Throughout this article, I will often refer to the ARM architecture and the x86 (also known as i386 or i486 or i686). The architecture simply refers to the CPU &#8220;design&#8221; and it&#8217;s a quick way of knowing what compiled code will work with which CPUs. The differences between each architecture and the reason for such differences is way beyond the scope of this article. Just keep in mind that when you select a compiler, an application or Linux distribution for you computer, you&#8217;ll probably be looking for the i386 (most Linux distributions will but different versions for i386 and i686, newer PCs run with i386) or the x86_64 (or x64) if you have a 64 bit processor. Note that i386 will work on 64 bit processor the the opposite is not true!</p>
<p><strong>Let&#8217;s get started</strong></p>
<p>First let&#8217;s assume that you have you environment set up, that you have some basic knowledge of Linux and that your code compiles on you current processor. Let&#8217;s also assume you&#8217;re not using some obscure libraries that you don&#8217;t have the source code for. Finally, I&#8217;ll assume that you have <em>ROOT</em> privileges on your system.</p>
<p>First step of the cross-compiling process is to locate the <em>toolchain</em> and download it to your home directory.</p>
<p>Next step is to extract it. If it&#8217;s a tarball, just execute the following command:</p>
<pre>tar -xzf crosstool.tar</pre>
<p>Once you have the content of the <em>toolchain</em> in a folder somewhere, we need to make it usable. This is where most people go their own ways. I found a very simple and effective way of using the <em>toolchain</em> and I&#8217;m sharing it because I think the other methods are more trouble than they are worth.</p>
<p>To get the <em>toolchain</em> working, let&#8217;s start by making a backup or our compilers. Execute the following commands in the console:</p>
<pre>cp /usr/bin/gcc /usr/bin/gcc.bak</pre>
<pre>cp /usr/bin/g++ /usr/bin/g++.bak</pre>
<p>Now that we have the backup done, we&#8217;ll remove the originals by running the following commands:</p>
<pre>rm /usr/bin/gcc

rm /usr/bin/g++</pre>
<p>And finally, we need a way of letting the OS think that we still have the compilers there, so we&#8217;ll add two symbolic links that will point to the <em>toolchain&#8217;s</em> compilers</p>
<pre>ln -s /path/to/crosstool/bin/crosstool-name-gcc /usr/bin/gcc      
ex: ln -s /home/test/arm-none-linux-gnueabi/bin/arm-none-linux-gnueabi-gcc /usr/bin/gcc

ln -s /path/to/crosstool/bin/crosstool-name-gpp /usr/bin/gpp               
ex: ln -s /home/test/arm-none-linux-gnueabi/bin/arm-none-linux-gnueabi-gpp /usr/bin/gpp</pre>
<p>Now that, we have some shinny new compilers, let&#8217;s test them with something simple. We&#8217;ll make a short &#8220;Hello World&#8221; program and compile it for your embedded device architecture. Type into a new file somewhere:</p>
<pre>#include &lt;stdio.h&gt;

int main(void) {

       printf("Hello World!\n");

       return 0;

}</pre>
<p>and save it as <em>hello.c.</em></p>
<p>To compile, you can simply type the following command (assuming that you are executing that command from the same folder that contains the file):</p>
<pre>gcc hello.c -o hello.arm</pre>
<p>You should look for errors here, if it succeeds, you should not get anything back and you will be able to see the file in your current folder.</p>
<p>Finally, to confirm that you have a working environment, we will look at the file properties by executing the command:</p>
<pre>file hello.arm</pre>
<p>if the output specifies the embedded device&#8217;s processor, you should be fine. It should look like:</p>
<pre>hello.arm: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.4.17, not stripped</pre>
<p>In part two of this tutorial, we will look at getting the original compilers back in and some advanced method for larger application compiling. Even though I am not an expert on the subjet, feel free to post your issues and questions and I will do my best to find and provide answers!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.talkcomputer.net/2009/05/compiling-for-embedded-processors-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
