<?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>Alejandro Segovia Azapian</title>
	<atom:link href="http://www.alejandrosegovia.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.alejandrosegovia.net</link>
	<description>Computer Engineer, Programmer, Geek.</description>
	<lastBuildDate>Sat, 22 May 2010 06:19:42 +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>Create Static Libraries using GCC</title>
		<link>http://www.alejandrosegovia.net/2010/05/22/create-static-libraries-using-gcc/</link>
		<comments>http://www.alejandrosegovia.net/2010/05/22/create-static-libraries-using-gcc/#comments</comments>
		<pubDate>Sat, 22 May 2010 06:13:31 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Labs]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.alejandrosegovia.net/?p=22</guid>
		<description><![CDATA[Static libraries provide a mechanism by which we can &#8220;pack&#8221; object code into reusable libraries. In this article I&#8217;m going to focus on creating static libraries of C (and C++) objects and functions. Let&#8217;s get started. Creating a static library is actually a very easy process that consists in just two simple steps: Compiling source [...]]]></description>
			<content:encoded><![CDATA[<p>Static libraries provide a mechanism by which we can &#8220;pack&#8221; object code into reusable libraries. In this article I&#8217;m going to focus on creating static libraries of C (and C++) objects and functions. Let&#8217;s get started.</p>
<p>Creating a static library is actually a very easy process that consists in just two simple steps:</p>
<ol>
<li>Compiling source code into object code.</li>
<li>Archiving all the generated object code into a single file that represents the library.</li>
</ol>
<p>Assume we have the following C source files that declare a 3-element vector type and a dot function that calculates the dot product among two vectors:</p>
<pre class="brush:cpp">/** algebra.h **/

#ifndef ALGEBRA_H
#define ALGEBRA_H

typedef struct
{
	float x, y, z;
} Vec3;

void vec3Init(Vec3* v, float x, float y, float z);

float dot(Vec3* a, Vec3* b);

#endif //ALGEBRA_H</pre>
<pre class="brush:cpp">/** algebra.c **/

#include "algebra.h"

void vec3Init(Vec3* v, float x, float y, float z)
{
	v-&gt;x = x;
	v-&gt;y = y;
	v-&gt;z = z;
}

float dot(Vec3* a, Vec3* b)
{
	return a-&gt;x * b-&gt;x + a-&gt;y * b-&gt;y + a-&gt;z * b-&gt;z;
}</pre>
<p>We can use the following two commands to create a static library:</p>
<pre class="brush: bash">gcc -static -c algebra.c -o algebra.o
ar -rcs libalgebra.a algebra.o</pre>
<p>Please notice we have named our static library &#8220;libalgebra.a&#8221;. This is not just a random choice as a static library&#8217;s name must begin with &#8220;lib&#8221; and end with &#8220;.a&#8221; in order to be able to have GCC link new programs against it.</p>
<p>Now that our library is ready, we can redistribute it with the header file &#8220;algebra.h&#8221; so other programmers can use it in their applications.</p>
<p>In order to illustrate this point further, let&#8217;s write a simple C program that includes the header and links against our library:</p>
<pre class="brush:cpp">#include &lt;stdio.h&gt; /* printf */
#include "algebra.h" /* our library's header */

int main()
{
	Vec3 a;
	Vec3 b;
	vec3Init(&amp;a, 1.0f, 2.0f, 3.0f);
	vec3Init(&amp;b, 3.0f, 2.0f, 1.0f);
	printf("&lt;a,b&gt; = %.2f\n", dot(&amp;a,&amp;b));
}</pre>
<p>In the above example you can notice how we can liberally use data types and functions declared in our library as if they where part of this very same program.</p>
<p>Now, in order to compile, all we need is the &#8220;algebra.h&#8221; header, however, in order to have this program link, we have to use the &#8220;-l&#8221; (lowercase L) flag of the GCC compiler to specify our shared library, like so:</p>
<pre class="brush:bash">gcc main.c -L. -lalgebra
$ ./a.out
&lt;a,b&gt; = 10.00</pre>
<p>Given the &#8220;-lalgebra&#8221; flag, GCC will look for a file called &#8220;libalgebra.a&#8221; (hence the importance in the library&#8217;s naming convention). The &#8220;-L&#8221; flag tells GCC where this file is located.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.alejandrosegovia.net%2F2010%2F05%2F22%2Fcreate-static-libraries-using-gcc%2F&amp;linkname=Create%20Static%20Libraries%20using%20GCC"><img src="http://www.alejandrosegovia.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.alejandrosegovia.net/2010/05/22/create-static-libraries-using-gcc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>On Polymorphism in C++</title>
		<link>http://www.alejandrosegovia.net/2010/05/07/polymorphism-in-cp/</link>
		<comments>http://www.alejandrosegovia.net/2010/05/07/polymorphism-in-cp/#comments</comments>
		<pubDate>Fri, 07 May 2010 15:41:40 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.alejandrosegovia.net/?p=19</guid>
		<description><![CDATA[C++, as many other Object-Oriented languagues, provides many facilities for us to implement our Object Oriented Designs. In this post I talk about a feature which is not frequently discussed, but must be taken into account when implementing a class hierarchy that leverages polymorphism as part of its design. Let&#8217;s suppose we have a base [...]]]></description>
			<content:encoded><![CDATA[<p>C++, as many other Object-Oriented languagues, provides many facilities for us to implement our Object Oriented Designs.</p>
<p>In this post I talk about a feature which is not frequently discussed, but must be taken into account when implementing a class hierarchy that leverages polymorphism as part of its design.</p>
<p>Let&#8217;s suppose we have a base class (conveniently named &#8220;Base&#8221;) and a derived class (conveniently called &#8220;Derived&#8221;) that extends &#8220;Base&#8221; through Public Inheritance.</p>
<p>If you don&#8217;t know what &#8220;Public Inheritance&#8221; means, all you really need to know for the purpose of this article is that there are three different kinds of inheritance in C++: public, protected and private. Public Inheritance is akin to inheritance in other programming languages such as Java, Python, Objective-C and C#.</p>
<p>Going back to our example, I&#8217;ve coded the Base and Derived classes&#8217; interfaces in the following snippet:</p>
<pre class="brush:cpp">#include &lt;iostream&gt;
using std::cout;
using std::endl;

class Base
{
	public:
		Base();
		virtual ~Base();
		virtual void printClassName() = 0; // =0 means "abstract"
};

class Derived : public Base
{
	public:
		Derived();
		virtual ~Derived();
		virtual void printClassName();

};</pre>
<p>Now, for the implementation, I want to have every object whose class is derived from &#8220;Base&#8221; to have its classname printed upon creation. So, what I am going to do is add a call to printClassName() in Base&#8217;s constructor.</p>
<pre class="brush:cpp">Base::Base()
{
	this-&gt;printClassName();
}

Base::~Base()
{
}

Derived::Derived() : Base()
{
}

Derived::~Derived()
{
}

void Derived::printClassName()
{
	cout &lt;&lt; "\"Derived\"" &lt;&lt; endl;
}</pre>
<p>This is the program entry point:</p>
<pre class="brush:cpp">// program entry point
int main()
{
	Derived* d = new Derived(); //print "Derived"
	delete d;
	return 0;
}</pre>
<p>If you know your Patterns, by now you&#8217;ll probably have noticed by now that this example is just an implementation of the Factory Method pattern, where I&#8217;m relying in a virtual method for leveraging derived-class-specific behavior in the Base class.</p>
<p>The problem here is that, when we try to compile this program, we get the following error:</p>
<pre class="brush:bash">ale@syaoran factory]$ g++ main.cpp -Wall
Undefined symbols:
  "Base::printClassName()", referenced from:
      Base::Base()  in ccNxv98U.o
      Base::Base()  in ccNxv98U.o
ld: symbol(s) not found
collect2: ld returned 1 exit status</pre>
<p>GCC is warning us that there is no implementation for the abstract method &#8220;printClassName&#8221; in class &#8220;Base&#8221;, and it aborts!</p>
<p>Why does this happen? The compiler certainly should not be trying to find an implementation for an abstract method after all. The reason this happens is because of how inheritance works in C++.</p>
<p>When an object whose class is derived from another class is instantiated, what happens in C++ is that, in order to create this object, an inner instance of its base class is created first. In our example, when calling Derived&#8217;s constructor, Base&#8217;s constructor is called first.</p>
<p>This actually implies that the derived object does not exist until the the inner base object is created.</p>
<p>In turn, this means that the derived object&#8217;s vtable (used for implementing Polymorphism in C++) does not exist when the base class&#8217; constructor is executing, so the compiler assumes that the base class&#8217; implementation of the method has to be invoked, and that triggers the link error.</p>
<p>Even worse would be the case if the method was not abstract (but still virtual). In this case the program would build fine, but, at runtime you would find out that the base class&#8217; implementation is being called instead of the derived class&#8217;.</p>
<p>How can you fix this problem?</p>
<p>Fortunately, the solution is simple, all you have to do is adopt the following gold rule:</p>
<blockquote><p>Never call virtual methods on a partially-created object.</p></blockquote>
<p>In order to fix our program, what I&#8217;m going to do first is to remove the printClassName call from Base&#8217;s constructor.</p>
<p>So, where should I place it now? Well, depending on the application it could be someplace or another. Since I would not like to change my design, what I&#8217;m going to do here is to separate the object construction into two phases: construction and initialization.</p>
<p>Construction will be carried out by the constructors, and initialization will be carried out by a special init() method that we can call once all the base objects have been created.</p>
<p>This separation will allow us to work safely, as all constructors will have executed when init() is called.</p>
<p>Applying these changes, the program will now look like this: the header for the Base class will include a new init() method:</p>
<pre class="brush:cpp">#include &lt;iostream&gt;
using std::cout;
using std::endl;

class Base
{
	public:
		Base();
		virtual ~Base();
		virtual void init(); // new: two-phase initialization
		virtual void printClassName() = 0; // =0 means "abstract"
};</pre>
<p>And the base class&#8217; implementation will implement init() as to call our virtual method:</p>
<pre class="brush:cpp">void Base::init()
{
    printClassName();
}</pre>
<p>At this point the program should build fine and, when run, should produce the following result:</p>
<pre class="brush:bash">[ale@syaoran factory]$ ./a.out
"Derived"</pre>
<p>As a final note, it would be possible to hide the call to init() into the Derived class&#8217; constructor, but this will only work as long as Derived is the last class is the hierarchy.</p>
<p>As soon as we add a &#8220;Derived2&#8243; class that inherits from Derived, we will have to refactor the call to init() into Derived2&#8242;s constructor, and so forth.</p>
<p>It would be interesting to see whether this problem arises in other programming languages. This will be left as an exercise for the reader.</p>
<p>You can find more information on abstract (pure virtual) methods and problems related to them <a href="http://www.artima.com/cppsource/pure_virtual.html">here</a>.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.alejandrosegovia.net%2F2010%2F05%2F07%2Fpolymorphism-in-cp%2F&amp;linkname=On%20Polymorphism%20in%20C%2B%2B"><img src="http://www.alejandrosegovia.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.alejandrosegovia.net/2010/05/07/polymorphism-in-cp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C as a programming learning language</title>
		<link>http://www.alejandrosegovia.net/2010/02/09/c-as-a-programming-learning-language/</link>
		<comments>http://www.alejandrosegovia.net/2010/02/09/c-as-a-programming-learning-language/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 21:58:48 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[Article]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.alejandrosegovia.net/?p=12</guid>
		<description><![CDATA[Recently we were talking with a colleague from my University about how programming is taught nowadays in college. In my University, the programming language used for teaching how to program is Java. I was discussing with a colleague the disadvantages I saw in using it as a language for teaching programming basics and why, in [...]]]></description>
			<content:encoded><![CDATA[<p>Recently we were talking with a colleague from my University about how programming is taught nowadays in college.</p>
<p>In my University, the programming language used for teaching how to program is Java. I was discussing with a colleague the disadvantages I saw in using it as a language for teaching programming basics and why, in my mind, it didn&#8217;t stack up against teaching a language such as plain C. The following story aims to reproduce the high points in the conversation.</p>
<p>Suppose you are a first year professor, teaching programming fundamentals, and I&#8217;m one of your students.</p>
<p>How would you start? If you&#8217;re anything like me, the first &#8220;hands-on&#8221; lab, you&#8217;ll probably write a classic &#8220;Hello World&#8221; program on the whiteboard and ask your students to copy that.</p>
<p>In order to do so, you instruct them to open up their &#8220;IDEs&#8221;, create a new class and copy that into a &#8220;method&#8221;&#8230;</p>
<p>Wait&#8230; what? As your student, chances are that by now, I&#8217;m probably wondering what an &#8220;IDE&#8221; is anyway.</p>
<p>As a teacher on a basic programming course, you&#8217;ll probably just tell me that IDEs are used for programming and that I&#8217;ll most likely have to use that every time I want to write a program (otherwise, what are we using it for?)</p>
<p>Okay, but &#8220;why don&#8217;t I have to use an IDE every time I want to use an application in my Windows&#8221;? Bam&#8230; now you must either explain the difference between code &#8220;in development&#8221; and code &#8220;in production&#8221; or ask me just to trust you and please focus on the example on the board for now.</p>
<p>Okay, let&#8217;s move on. You said I had to copy what you wrote into a &#8220;class&#8217; main method&#8221;&#8230; What is a &#8220;class&#8221; and what is a &#8220;method&#8221;? Ahh, okay. Here, you are trapped. Clearly these are OOP concepts, and you certainly don&#8217;t want to start digging into that before your students even write their first &#8220;Hello World&#8221; application. All you can do here is to ask them, once again, to just trust you by saying that &#8220;that&#8217;s the way things work in Java&#8221;.</p>
<p>So, your students have finally created a project in an &#8220;IDE&#8221;, created a &#8220;class&#8221;, defined a &#8220;public static&#8221; &#8220;method&#8221; and wrote the snippet you typed at the whiteboard in their IDE&#8217;s text editor.</p>
<p>The final code looks something like this:</p>
<pre class="brush:java">public class HelloWorld
{
    public static void main(String[] args)
    {
        System.out.println("Hello, world!");
    }
}</pre>
<p>They press &#8220;Play&#8221; on their &#8220;IDEs&#8221; and it just works. Everything is good.</p>
<p>Quick question: how many things in this code do you think are completely strange to your students? Probably all of it, since it&#8217;s the first time they&#8217;ve seen a program being coded. That&#8217;s okay, but how many of these things do you think are feasible to be explained in a programming 101 course? just <em>println</em>, maybe?</p>
<p>Why? Because in order to explain what a &#8220;class&#8221; is, what a &#8220;method&#8221; is, what &#8220;public&#8221;, &#8220;static&#8221;, &#8220;String[]&#8220;, &#8220;System&#8221; and &#8220;out&#8221; mean, you have to start digging into OOP concepts from day one. And you don&#8217;t want to do that, because chances are 1) you&#8217;ll end up confusing everyone and 2) most of that stuff will not really be useful for the course at all!</p>
<p>So&#8230; if teaching this way seems to be so complicated, why are we using Java for teaching programming? Well, I think we shouldn&#8217;t. C would be a much better candidate.</p>
<p>Compare the previous Java program with the following C equivalent:</p>
<pre class="brush:cpp">#include &lt;stdio.h&gt;
int main()
{
    printf("Hello, world!");
    return 0;
}</pre>
<p>Which one do you think is easier to explain? At most, what your will probably end up asking is &#8220;what does #include mean?&#8221;. You can just answer that it&#8217;s a file where printf is defined. That&#8217;s it. No strings attached. No &#8220;public static void Main(String[] args)&#8221;. Just a plain and simple <em>printf</em>.</p>
<p>What about all that &#8220;IDE&#8221; mess? Well, it turns out you can just use a plain text editor with some syntax highlighting and a C compiler and you are good to go. Compiling C code is extremely simple, if the system is correctly configured. Just issuing a command like the following will be enough for producing an executable file:</p>
<pre class="brush:bash">gcc hello.c -o hello.exe</pre>
<p>It&#8217;s that easy. And best of all is that you get an executable. A plain .exe file on Windows. That&#8217;s what your students <strong>are</strong> expecting. That&#8217;s what a program <strong>is</strong> to them. An .exe file! In Java, your compiler would&#8217;ve generated a &#8220;.class&#8221; file, and then you would have to teach your students how to invoke the Java Virtual Machine, explain what a Runtime is and why is it needed to have your code (which is already complied, isn&#8217;t it?) run.</p>
<p>Another final advantage? By asking them to compile their code by hand, you indirectly have them learn how to use the Terminal application (believe me, most students don&#8217;t know what that is or how it&#8217;s used nowadays) and you are laying the foundation for them to learn how to use a non-GUI operating system.</p>
<p>You can achieve all this (and more) without having to ask them to &#8220;trust you&#8221; or to hold their questions for one to two <strong>years</strong>, until they have their first OOP course.</p>
<p>You could argue that, even though Java might seem more complicated at first, it&#8217;s more popular and thus it could never be a mistake to teach it. I completely agree, but I think it should be taught as a second or third language, not as the first one. Not only does Java require the student to wait until he or she goes through 2 or 3 programming courses in order to be able to fully &#8220;get&#8221; the language, but also, there are some concepts that they will just never learn this way, such as memory management or pointers.</p>
<p>So, please, if you&#8217;re a programming 101 teacher who&#8217;s doing Java, I ask you to reconsider. C does not have to be hard, and your students will thank you for conducting a exhaustive, self-contained course.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.alejandrosegovia.net%2F2010%2F02%2F09%2Fc-as-a-programming-learning-language%2F&amp;linkname=C%20as%20a%20programming%20learning%20language"><img src="http://www.alejandrosegovia.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.alejandrosegovia.net/2010/02/09/c-as-a-programming-learning-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Create Shared Objects under Mac OS X</title>
		<link>http://www.alejandrosegovia.net/2010/02/09/how-to-create-shared-objects-under-mac-os-x/</link>
		<comments>http://www.alejandrosegovia.net/2010/02/09/how-to-create-shared-objects-under-mac-os-x/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 20:07:56 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[Labs]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.alejandrosegovia.net/?p=9</guid>
		<description><![CDATA[Some time ago a friend from Colombia asked me how to create a Shared Object under Mac OS X in order to be able to use it from a Python application (via ctypes). Although the compiler most commonly used on Mac OS X is the GCC compiler, the version supplied by Apple has a handful [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago a friend from Colombia asked me how to create a Shared  Object under Mac OS X in order to be able to use it from a Python  application (via ctypes).</p>
<p>Although the compiler most commonly used on Mac OS X is the GCC  compiler, the version supplied by Apple has a handful of modifications  which are specific for OS X. In particular, the -shared compiler flag,  used to create Shared Objects under GNU/Linux based systems, has no  effect.</p>
<p>In spite of this, Apple did introduce its own mechanism for creating  Shared Objects along its GCC extensions. Assuming we have a file called  mylibrary.c, which contains the source code for our library, we should  invoke GCC like so:</p>
<pre class="brush:bash">gcc -dynamiclib mylibrary.c -o mylibrary.dylib
</pre>
<p>If the compiling process succeeds, this command should create a file  called mylibrary.dylib, which can now be dynamically linked from other  applications.</p>
<p>Unlike Linux based Operating Systems, Mac OS X seems to automatically  add the current working directory to the DYLD_LIBRARY_PATH environment  variable (an equivalent to Linux’s own LD_LIBRARY_PATH), thus it should  not be required to modify this variable in order to have our  applications link against the newly created library at runtime, unless,  of course, we wanted to move the Shared Object to a directory different  from where our process will be executing.</p>
<p>Finally, it should be taken into account that this mechanism is just a  simplified example. A correct way to manage the library creation  process would be by means of make or equivalent software construction  applications, which provide several advantages to software developers.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.alejandrosegovia.net%2F2010%2F02%2F09%2Fhow-to-create-shared-objects-under-mac-os-x%2F&amp;linkname=How%20to%20Create%20Shared%20Objects%20under%20Mac%20OS%20X"><img src="http://www.alejandrosegovia.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.alejandrosegovia.net/2010/02/09/how-to-create-shared-objects-under-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to turn an Ubuntu desktop into a convenient Linux-based server</title>
		<link>http://www.alejandrosegovia.net/2010/02/09/how-to-turn-an-ubuntu-desktop-into-a-convenient-linux-based-server/</link>
		<comments>http://www.alejandrosegovia.net/2010/02/09/how-to-turn-an-ubuntu-desktop-into-a-convenient-linux-based-server/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 19:59:41 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[Labs]]></category>
		<category><![CDATA[Server Config]]></category>

		<guid isPermaLink="false">http://www.alejandrosegovia.net/?p=6</guid>
		<description><![CDATA[If you have a desktop computer and a laptop chances are that, in the long run, you end up spending more time working on your laptop than on your desktop. If repurposing your old desktop into a fully fledged server seems like too much of a commitment (either because you do not have the time [...]]]></description>
			<content:encoded><![CDATA[<p>If you have a desktop computer and a laptop chances are that, in the long run, you end up spending more time working on your laptop than on your desktop. If repurposing your old desktop into a fully fledged server seems like too much of a commitment (either because you do not have the time to set it up or do not want to give up your desktop), you can still configure it as to offer services to other computers on your network without having to go for a server operating system.</p>
<p>Accessing a computer from your local network usually just means assigning an static IP address to your desktop and have it though that IP address every time. The peculiarity with desktop Linux distributions -such as Ubuntu or Fedora- is that they now ship with an utility called NetworkManager which tries to make it “simple” to manage networks. The problem with NetworkManager is that, in my opinion, it was designed mostly for a mobile scenario, where a laptop moves around and tries to join different networks along the way, but this is rarely the case for a desktop computer, which just connects to the same network every time. Furthermore, depending on your router configuration, it may prove difficult to impossible to have a NetworkManager-enabled desktop PC to have the same IP address assigned every time the computer joins the DHCP network.</p>
<p>In this post we will present a method for completely disabling NetworkManager from your Ubuntu desktop system and, using the old-school Linux networking facilities, have your desktop computer’s network connection set up your way, offering services to other computer without sacrificing Internet access.</p>
<p><span id="more-6"></span>This article has been tested on Ubuntu 8.04.</p>
<p><strong>Step 1 – Disabling NetworkManager</strong></p>
<p>NetworkManager handles all network connections, preventing us from manually configuring our host the way we want to. The first step to take consists in disabling NetworkManager once and for all. We use the following Terminal commands (as root):</p>
<p>sudo service NetworkManager stop</p>
<p>sudo rm `find /etc/rc* -name “*NetworkManager”`</p>
<p>The first command stops NetworkManager, whereas the second one removes every NetworkManager entry from the Linux runlevels, effectively preventing it from automatically starting the next time the system is started.</p>
<p>Although it is not strictly necessary, it would be “elegant” to remove the GNOME NetworkManager applet from the desktop environment as well. This can be disabled from the “System -&gt; Preferences -&gt; Sessions” configuration panel just by unchecking the corresponding entry. This will prevent the applet from automatically staring the next time we log in. If we wanted to stop the currently executing applet without having to logout and log in again, we could stop the “nm-applet” or “nm-gnome-applet” process from the Terminal using the kill command.</p>
<p><strong>Step 2 – Configuring our Network Interface</strong></p>
<p>Without NetworkManager in the way, we can define and configure our Network Interface the way we want to. We just need to edit the /etc/network/interfaces file and add the following configuration. We will name our interface “eth0″ and assign an IP address of “192.168.1.50/24″, but you can set the interface to any values you desire. This has to be done as root.</p>
<p>auto eth0</p>
<p>iface eth0 inet static</p>
<p>address 192.168.1.50</p>
<p>netmask 255.255.255.0</p>
<p>broadcast 192.168.1.255</p>
<p>gateway 192.168.1.1</p>
<p>The first line is of special importance. It declares eth0 as an interface that has to be enabled automatically when the system is booting. Now we must set the DNS servers this host will use for resolving domain names. In order to set this servers, we must edit the file: /etc/resolv.conf (again as root) and we add the following lines (this is Uruguay-specific):</p>
<p>nameserver 200.40.30.245</p>
<p>nameserver 200.40.220.254</p>
<p>Once the changes have been written to disk, we can restart the network in order to make sure our changes were correct:</p>
<p>sudo service networking restart</p>
<p>Having restarted the host’s network configuration, we can verify the active interfaces using the “ifconfig” command. If our changes were correct, we should now be connected to the network, being able to browse the Internet without difficulties and with an static IP address of 192.168.1.50.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.alejandrosegovia.net%2F2010%2F02%2F09%2Fhow-to-turn-an-ubuntu-desktop-into-a-convenient-linux-based-server%2F&amp;linkname=How%20to%20turn%20an%20Ubuntu%20desktop%20into%20a%20convenient%20Linux-based%20server"><img src="http://www.alejandrosegovia.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.alejandrosegovia.net/2010/02/09/how-to-turn-an-ubuntu-desktop-into-a-convenient-linux-based-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Sudden Change of Plans&#8230;</title>
		<link>http://www.alejandrosegovia.net/2010/02/09/hello-world/</link>
		<comments>http://www.alejandrosegovia.net/2010/02/09/hello-world/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 02:05:11 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[Blog Admin]]></category>

		<guid isPermaLink="false">http://www.alejandrosegovia.net/?p=1</guid>
		<description><![CDATA[For a looong time I was wondering whether it would be best to start a blog in English or in Spanish. Being fluent in both languages provided me the freedom to pick one or the other. About three years ago, I decided Spanish was the way to go (being my Mother Tongue after all), but [...]]]></description>
			<content:encoded><![CDATA[<p>For a looong time I was wondering whether it would be best to start a blog in English or in Spanish. Being fluent in both languages provided me the freedom to pick one or the other.</p>
<p>About three years ago, I decided Spanish was the way to go (being my Mother Tongue after all), but at times, I couldn&#8217;t stop wondering if I was sort of crippling my blog by limiting it to the Hispanic society exclusively.</p>
<p>All this wondering was more than just occasional thoughts it seems, since as of today, I finally decided to launch an English blog.</p>
<p>I wanted to consolidate several websites and ideas under the same &#8220;roof &#8220;, and this is it. Here I plan to publish tutorials, personal info, and thoughts about technology (specifically Computer Graphics and Linux and Mac development) as well as about my company, <a href="http://web.algorithmia.net">Algorithmia</a>.</p>
<p>Feel free to look around. I hope you find the site useful. Welcome.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.alejandrosegovia.net%2F2010%2F02%2F09%2Fhello-world%2F&amp;linkname=A%20Sudden%20Change%20of%20Plans%26%238230%3B"><img src="http://www.alejandrosegovia.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.alejandrosegovia.net/2010/02/09/hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
