|Personal||By Shamus||Dec 20, 2012||183 comments|
If I’m going to indulge this pipe-dream of Linux-using, then it’s time to stop fussing around in Minecraft and work on something serious. It’s time to see if I can use Linux to program. If I can’t do that, then I ought to walk away now before I get too comfortable.
Going by the comments yesterday, it seems like Eclipse is the go-to IDE for coders on Linux. (IDE means “Integrated development environment”, and is to coding what a word processor is to writing) I open the Software manager and install it. It seems to work fine, except…
For a quick test, I input the classic Hello World program to find that Eclipse can’t find <stdio.h>. This is very strange. I expected some confusion and growing pains in moving to Linux, although I didn’t expect them quite this soon or quite this simple. For completeness, I try the C++ variant of Hello World, and discover that it doesn’t know what to make of <iostream>.
This is such a basic, fundamental failure that I don’t know where to begin. Imagine if word processors would only let you use a word if it was in the dictionary. Now imagine a word processor that came without any dictionary. That’s what we have here. This is a C development environment that doesn’t know C.
Is this a problem with Eclipse? A problem with my Linux install? A problem with how I set up this project? I don’t know, and so I don’t know where to look for answers. In bemused frustration (yes that’s possible) I turn to Twitter. My tweeps suggest that code::blocks is a good IDE to use. So I install that.
Installing code::blocks also manages to install whatever files were missing and preventing Eclipse from working properly. This is the first sign that we’re not in Kansas anymore, Toto. In Windows, programs tend to keep to themselves. If I install Visual Studio, it will install <stdio.h>, <iostream>, and the thousands of other files that a compiler needs. If I then install (say) Qt Creator, it will need its very own copy of those files – even if the files are identical, down to the last character. There are situations where Windows programs share, but generally not stuff like this. Eclipse and code::blocks are obviously drawing from the same pool of files.
So now I have two IDEs working. I have decided to keep them both for now, and pit them against one another. The one that confuses / irritates / hassles me the least will be the winner and become my IDE of choice. The other one will… actually, no. I don’t dare uninstall the loser, lest it take those shared files with it to oblivion. So the loser will remain installed and I’ll just have to remember to make a point of not clicking on it. That’ll teach it.
Well, I’ve compiled Hello World, which is satisfying but not productive. If we’re going to write real code then we’ll need real tools. We might as well solve the most difficult problem first: Window management and portability. Based on the suggestions yesterday, I’ve decided to build a little test application on GTK. It’s popular to the point of ubiquity and is available on both Linux and Windows. Anything I write that uses GTK ought to be able to compile on either platform.
When I want to use some code, the Windows tradition is to go to the website, download it, and then cuss at the install scripts in outraged bafflement until you give up and try something else. I assume that’s also how we do things here on Linux? I download GTK from the website and begin squinting at the ./configure scripts, trying to figure out how they should work, why they aren’t working now, and what I need to do to get them from here to there. GTK depends on no less than five other projects, although none of those projects seems to depend on anything. So our dependencies are broad but shallow. This is better than narrow but deep, but not nearly as good as “no dependencies”, which never happens because LOL GET A REAL PROGRAMING LANGUAG YOU FOSIL.
After about 45 minutes of frustration I haven’t made any headway. Even if I get this configuration script to work, I don’t understand where I’m supposed to put these files or how to tell the IDE where to find them. This is because there are only two types of programming tutorials on the net:
- Buttons are useful! Here is how to identify a button, and how to use your finger to press one!
- Here is how to deal with a flame-out in an F/A-18 Hornet while on approach to a Nimitz class carrier. This tutorial is particularly focused on daytime scenarios. If this happens in nighttime fly conditions or you’re operating in sub-tropical weather, please consult a more appropriate guide.
There is no bridge between baby steps and ninjutsu. This problem is particularly bad in the C/C++ world where every development environment seems to have a slightly different (or radically different) solution, so it’s not possible for someone to write a sensible, general-purpose guide.
Eventually I discover that this business of downloading and configuring stuff manually is only for obscure packages or hardcore devs with exotic requirements. For most people, you can get stuff like this from the Software Manager. It works a bit like Windows Update, except it downloads all kinds of different software, themes, updates, tools, packages, and other nuggets of digital treasure. You can also do this using the terminal, which is how I discovered this feature, but sense I could really make a mess doing things that way. In one forum I find the example terminal command:
sudo apt-get install gtk2.0+-
Breaking this down for the curious:
sudo stands for “Super User DO“. It means you want to execute this command with root privileges, which are required for installing new stuff.
apt-get Stands for Advanced Packaging Tool get. The apt is used for downloading and installing new components, making sure they end up in the right places, and making sure the system knows where they are. Here you’re telling the apt to get something.
install means you want to install this thing. I’m sure this is obvious to you but explaining it allows me to feel superior and smart even though I have no idea what I’m doing.
gtk2.0+- means it should download the GTK package, version 2.0. I don’t know what the plus-minus stands for on the end.
The problem here is that GTK is now on version 3.6. Do I have it on my system already? Which version? If not, which version is best to get? Will any particular version cause conflicts with things I already have installed? (It shouldn’t, of course. We’re downloading source files, not executables. Still, I don’t know how this install might impact Eclipse or code::blocks, which might be changed, or what else might go wrong. In programming, what you don’t know can actually hurt you and is very likely to do so.
So I fire up the software manager and try to figure out if I have GTK, what version I have, and if I don’t have it, how to get it. This is very, very hard because GTK is used by a lot of programs. For example, the interface of GIMP is built on GTK. (Photoshop for Open Source hippies.) So in the software manager, the description is something like “GIMP using GTK library” or whatever. When I search for GTK packages, I get hundreds of results, wading through them takes forever, and I’m not even sure if I’m on the right track.
It’s like if you want to bake something with chocolate, so you do a search for just “chocolate”. The search results are clogged with chocolate cookies, chocolate cake, chocolate bar, chocolate frosting, chocolate chips, chocolate milk, chocolate Santas, chocolate bunnies, chocolate sprinkles, chocolate ice cream, chocolate mint, chocolate-covered *’s, chocolate flavor, chocolate color, chocolate-scented candles, chocolate cereal, chocolate syrup, chocolate substitutes, chocolate addiction, chocolate gifts, artificial chocolate flavoring, chocolate powder, removing chocolate stains, bulk chocolate, diet chocolate, kosher chocolate, vegan chocolate, lactose-free chocolate, gluten-free chocolate, and taxes on chocolate.
What about chocolate bars? Is that what you need? It kind of looks like it. Maybe you’re supposed to melt it down. But it’s got sugar in it, and your recipe calls for sugar. Hmmm.
Of course, the phrase you’re looking for is “BAKING CHOCOLATE”. If you know this then the search is stupid easy and if you don’t then the search is impossible. In my case, the phrase I was looking for is “libgtk”. It turns out that terminal command above was incorrect. (Or old. Or both.) By narrowing my search to libgtk I’m able to find the components for building GTK applications. There are many, and I seem to have everything except the core files. The version available in software manager is 3.0 and the latest is 3.6, but I’m betting (hoping!) that the 3.0 version is just fine and was chosen because it was the version with the least potential conflicts.
So I install it.
I try #including <gtk.h> in both Eclipse and code::blocks, which naturally doesn’t work. Do I need to make it <gtk/gtk.h>? Or perhaps <gtk3-0/gtk/gtk.h>? Or maybe <gtk3-0/gtk.h>? I find examples and variants of all of these in searches, none of them work, and I have no idea how to do this amazingly simple, straightforward thing. I don’t know where these files are on my computer, how to find them, or how to tell my IDE how to find them. (I search file system for gtk.h, and a long search turns up bupkis.)
This is pretty demoralizing. In the time I’ve sunk into this so far I could have installed Windows 7 and Visual Studio and just returned to work. I wouldn’t mind if I felt like I was making progress, but I really didn’t expect to spend two and a half hours trying to write my first line of code. The problem with situations like this is that you don’t know how deep the rabbit hole goes. I could solve this problem thirty seconds from now. Or maybe it will take another hour. Maybe when I solve this problem there will be another one that will require a similar investment of time. Maybe I’ll get stuck on a new compile problem. Or a linker problem. Or an execution problem. There’s no limit to how many things can go wrong or how long it can take to fix each one.
It’s entirely possible I’ll slam away at this problem, fix it, and run into another problem that’s baffling and insurmountable. Even if you’ve got a good friend who is really patient and knows all about this sort of thing, answers to these sorts of questions often begin with, “Well, depending on your setup…”
It’s like a game of chance where you keep betting time, and if you win all you get is the chance to make another wager. How much time do you put in before you conclude this isn’t going to pay off?
I’m going to go play Minecraft until I get enough patience to continue.