The first few days of working with Linux are always the roughest. There are innumerable little twists and tricks that you need to just accomplish the simplest things. But once you gotten through this initial trial, things become much easier.
I am feeling generous right now because I just finished successfully porting my gear program from Windows to Linux and then back. The number of changes I had to make on the return to Windows are few enough (2) that I am confident that this version will compile and run unchanged on the Linux system.
Geez, what a struggle it was to get here though. First there was just getting the screen resolution up to something usable. Okay, I've gotten a little spoiled. I remember when 640 by 480 was perfectly adequate, now I'm running 1280 by 1024 on my Windows machine. It makes the 1024 by 768 on the Linux box look a little feeble, but I've managed to adjust.
So I mail the source files to myself and download the zip file from my gmail account using Firefox on Linux. That part actually works. Start work on a makefile, try compiling. The graphics include files are not here! Search the disk and still no luck. So now we venture into the swamp of Linux forums on the internet, trying to figure out what is going on. Eventually I run into something called Mesa, which seems like it might be what I am looking for. They have a pretty good explanation of what is required, so I download their three files and unzip them.
Type "make" in the terminal window and I get infinity errors. There are so many I cannot find the beginning even if I scroll back to the top of the very large terminal buffer. WTF? Back to the swamp. Finally stumble across some instructions for building "Micropolis", whatever that is, but they seem to be having similar problems. Seems if you want to build Mesa, there are about half a dozen other software packages you need to install. You don't need just one, or two, or three, you need all eight of them. I am not sure about number seven. I installed it out of order and it didn't help, but when I finally installed the last one, Mesa built without complaint.
OK, great. Now I should be good to go. Well, actually, my program compiles, which is really a good thing, but it won't link. Can't find the libraries. Can't even find the math libraries, the ones that contain things like sin and cos, you know, basic trig functions. Now that's pretty chickens**t. More slogging through the swamp and I find some very good instructions for gcc (the Linux compiler and linker and general all around beast of burden for programmers) which tells me how to specify libraries.
It also helps that I am able to puzzle out enough makefile/shell syntax to write a fairly concise makefile, something I used to be able to do in my sleep. All this gets rid of the unresolved references to the math functions, but I am not making any progress on the graphics functions. The error listing is now small enough that it does not overflow the terminal buffer, so I can go back to the beginning and study it at leisure. I always want to start with the first error because often times that is one that triggers the avalanche. So if you can fix the first one, all the other errors might disappear.
That is not the case this time. All I see if hundreds of unresolved references to graphics functions. I try changing libraries. Maybe I am not using the right one. I try changing library paths. I write test scripts to verify that what I am doing with these environment variables is what I intended. No help. I'm looking at the error listing again and I see this one line that is different from the rest, not very different, just a little different. Looking closer, I see it popping up in a couple of other places. It is totally cryptic, it means absolutely nothing to me, but shoot, let's see what Google can do with it.
Surprise, surprise, it leads me right back to the web site about the gcc compiler. Seems if you feed C++ files to gcc, it will compile them, but the object files it creates will be unlinkable. In other words, they are trash. If you want to compile C++ code, you should use g++ instead of gcc. Criminently, what a bunch of gooberness. There is hardly any C++ code in my program, so I chop it out and recompile and the funny errors go away. However, I am still stuck with the unresolved references to the graphics functions. It's late, I'm tired, I give up and go to bed.
This morning I get up and it's got me bugged, so I go back and try some variations on the graphics libraries, and presto! Compile and link success! I am still left with the question as to what the other libraries are for, especially the ones with the same names in different directories.
But hey, it compiled! Will it run? Sure it will! Give it a try, boom, error, fail, die. What's wrong now? More wallowing in the swamp, no luck here. Let's try the debugger. No luck. Maybe we need to compile a debug version. More consulting the gcc manual, change the compiler control, recompile, debug, step through the program, it can't open the configuration file! Bam! Hand to forehead, of course it can't, I was so concerned about getting to the run stage, that I neglected to copy the input data file.
This is one of these cases where a development crutch let me skip good programming practice. Under Visual C, if it can't find the file, the Visual C debugger will tell you. On Linux, it just hands you a big fat zero, and if you mistake that zero for a file handle and try to use it, boom, down you go in a heap. So we add another test to ensure that the system hasn't handed us a big fat zero instead of a file handle. Stupid system.
Put a copy of the input file where our program should be able to find it, compile and run, and zowie! There it is on the screen, bigger than Dallas! Little bitty gears going round and round and round. This is very cool.
Okay, but we've made a bunch of changes, minor, but changes nonetheless, so we need to go back to the Windows system and see if it will recompile and run over there. It doesn't right off, but all I have to do is add a conditional include of windows.h and everything is copacetic. The condition should fail on Linux, so it shouldn't look for windows.h and everything should be copacetic over there too. It better be.
P.S. Don't use angle brackets in your blog text. It makes things disappear.
Silicon Forest
If the type is too small, Ctrl+ is your friend
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment