Covered Topics

Please see the list of the topics I've covered. It's located near the bottom of the page. Thanks for stopping in!!

Friday, November 19, 2010

Using gcc and g++ To Compile Programs In A LINUX Or Windows Environment

Many LINUX and most UNIX users are familiar with the gcc and g++ compilers. GCC stands for the "GNU Compiler Collection". GCC supports C, C++, JAVA, and a few others. GCC and g++ are available for free for most distributions of LINUX and UNIX. Many folks have used these utilities for both school projects as well as actual production development. The "GNU Compiler Collection" is ideal for developers, students, hobbyists, or anyone else wanting to work with or learn C/C++, JAVA, or Fortran on a shoestring and NOT shell out major funds for a commercial product. CygWin g++ and MinGW are designed for Windows machines; I've posted a link concerning this near the end of this post.

The gcc utility supports C, whereas g++ also supports C++.

GCC may be operated either from the command line or via a graphical IDE (Integrated Development Environment). Some folks also use it from within the vim or emacs text editors. I will cover the Code::Blocks IDE environment in a future post.

These are operated from the command line using commands such as the following:

gcc file.c

or

g++ file.c

Various command line switches such as -o, -g, ... tell it to save to a specific output file name, use the gdb debugger, etc.

The gcc and g++ compilers, by default, output to a file named a.out, unless you use the -o switch.

To compile a program and output to a filename of your choosing, such as "My_File", you would do the following:

gcc file.c -o My_File

To quickly test my compiler, I typed out the ever popular "Hello World" program in my text editor as shown below:

#include

main() {
printf("Hello from Karl's Lab!\n");

return 0;

}

and saved it as "Hello_Test.c" in my home directory. I wanted an output file called "Hello_1". I also wanted debugger information. Here's the command I used:

gcc Hello_Test.c -g -o Hello_1

The "-g" switch activated the gdb debugger; the -o Hello_1 part told it to name the output file "Hello_1"; "the "Hello_Test.c" part told it the name of the source file to be used.

When I typed "Hello_1" without the quotes at the command line, I received the following output:

Hello from Karl's Lab!


See a Compiler error:

In C, you must use the ";" symbol at the end of a statement. I wanted to see how gcc responds to an actual error, so I removed the ";" symbol from the "printf" line in the code snippet above, then saved and compiled the code as before. Here's the message it returned:

Hello_Test.c: In function ‘main’:
Hello_Test.c:7: error: expected ‘;’ before ‘return’

The first line of information shows the function - "main" - the error occurred in. The second line of output shows which line number the error occurred in and there is a ";" symbol missing in the code. While the actual typo was in line 4 of the code, the 'return' statement at line 7 is where the compiler errored out. With this output, you are at least given somewhere to start in trouble-shooting your code.

See the gdb debugger work:

Suppose your working directory is /home/mike/c_progs, and your executable is My_File. The command you would enter at the command line is:

gdb /home/mike/c_progs/My_File

You will get something like the following:

Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...
(gdb)


At this (gdb) prompt, RUN "My_File" by typing "r" (without quotes).

(gdb) r

Starting program: /home/mike/c_progs/My_File
Hello from Mike!

Program exited normally.


This shows the program's output (Hello from Mike!), as well as that it executed without any errors or warnings.

When you are finished working, EXIT the gdb prompt by typing "q" without the quotes at the (gdb) prompt. This exits the debugger and returns you to the UNIX shell prompt.


Here are some good links on using gcc and g++ :

GCC's Homepage - Look here for the manuals to whatever version of gcc you have.
http://gcc.gnu.org/onlinedocs/

http://www.network-theory.co.uk/docs/gccintro/


Some good info for getting g++ for a Windows machine:

http://cocoon.cs.odu.edu/cocoon/~cs252/open/yourOwnCompiler/allPages.html


Here are some links to a good tutorial on the gdb debugger:

http://heather.cs.ucdavis.edu/~matloff/UnixAndC/CLanguage/Debug.html#tth_sEc3.2.1

and

http://www.cs.cmu.edu/~gilpin/tutorial/


The GCC Homepage:

http://gcc.gnu.org/

Monday, November 15, 2010

Test of Ubuntu 10.10 "live" CD




Yesterday I tested Ubuntu 10.10 - Maverick Meerkat "live" CD release.

After downloading the iso file and burning it to CD, I booted my dual core 1.8 MHz machine to it. It took about 2.5 minutes to boot from the P.O.S.T. screen to the desktop. As I said in my last post, this is about typical of my experience with a "live" CD boot.

Ubuntu 10.10 auto-detected my HP printer and prompted me to install the HPLIP utility and drivers. Very cool!

Other observations:

1) This distribution has Open Office
2) Screen capture applet shows in the screen captures here - I suspect this is a bug
3) NO Gnu Image Manipulation Program (GIMP)
4) The gcc compiler does come with the "live" CD
5) The buttons to close, expand, or reduce active windows have been moved to the upper left-hand side of the windows. Why Canonical, the makers of Ubuntu, decided to do this, I don't know. I'm used to these functions being in the upper right hand corner of the window and prefer it that way.
6) Still the same GNOME desktop - the "Unity" desktop we've been hearing about lately is to occur in an upcoming "11" release.
7) As with Fedora 14, setting up my broadband access was a snap. A browser window may be seen in the following screenshot



I did not bother to try it on my 800 MHz Pentium III machine due to hardware issues.

You can get your own copy of Ubuntu 10.10 here:
www.ubuntu.com

Thursday, November 11, 2010

Test Of Fedora 14 'Live' CD Release

Last night, I decided to stay up late and try out the Fedora 14 live "Laughlin" CD release. I burned a CD from the iso file and booted my dual core machine to it. This machine is 1.8 MHz with 1 GB of RAM. Boot time was 1 minute 45 seconds. About typical in my experience for a CD ROM "live" run - booting from a CDROM and running the system entirely in RAM causes a bunch of latency you don't get in a "normal" installation. I figure a hard drive install will cut the boot time by about 2/3.




At two minutes, the desktop appeared as in the picture above. Fedora auto-detected my broadband connection, and Internet connectivity was easy and fast to set up. On checking the drop-down menu boxes, several things became apparent:


1) NO office productivity suite. Not surprising, as even as far back as Fedora Core 10, there was no office suite. I wonder if this has anything to do with the recent acquisition of Sun Microsystems and Open Office by Oracle. What WAS surprising to me was AbiWord wasn't even included. F.C.-10 at least included AbiWord.
2) NO GIMP - the GNU Image Manipulation Program. Not a huge problem, but past releases of Fedora had it and Ubuntu had it as of 10.04.
3) Firefox 3.6.10 - the most recent release - was included.
4) NO gcc, nmap, wireshark, or much else. What you are getting in the 'live' CD distro is a bare-bones system that will allow you to get online to download all the stuff you need for a decent system. As I found with Ubuntu 10, Ubuntu doesn't give you what they used to on the 'live' CD either. Would be interesting to try out a current Knoppix distro.

Subjective Impressions:
Once fully booted up, performance seemed average compared to my current Fedora hard drive installation. Online browsing with Firefox worked well with no apparent glitches. A browser window can be seen in the picture here.



Older, slower PIII system test:
Next, I tried the CD in my 800 MHz PIII 'coppermine' machine with 1 GB of RAM. This system normally runs acceptably well with an old Ubuntu 8.10 installation, but would NOT win any speed awards.

The first attempt at booting hung at two minutes into the game. I rebooted the machine and after four minutes got the desktop. While the mouse cursor moved about the desktop OK, the response when selecting menu items was extremely sluggish - to the point of being unusable.

This may NOT have been a fair test. I suspect it is developing some hardware issues; it does occasionally hang when booting Ubuntu 8.10. This was NOT a problem back in early 2009 when I first configured that system with Ubuntu 8.10, but it is increasingly so now. Another item I noticed is there were several error messages seen early during both boot attempts.

I don't have another working PIII system to test with, but I suspect FC-14 would work OK on this platform given more RAM (2 GB or more) and reliably functioning hardware.

Wednesday, November 10, 2010

Fedora Core 14 LINUX

I recently downloaded the latest Fedora LINUX "live" CD release - Fedora Core 14. Hopefully within the next week or so I'll be able to actually test it. When that happens, I'll post the results and a couple screenshots here. Meanwhile I've been tied up with doing pre-winter maintenance on my truck, along with handling some other urgent personal matters.

Here is the link to the release notes for Fedora 14:
http://docs.fedoraproject.org/en-US/Fedora/14/html/Release_Notes/index.html

Get your very own copy of Fedora 14 here:
http://fedoraproject.org/en/get-fedora

If you want to try the desktop upgrade feature, you will need the "PreUpgrade" application. Go to http://fedoraproject.org/wiki/Upgradingfor more info.

In other news ...
I also plan to download and test out the new release of Ubuntu. Ubuntu has apparently switched from the traditional GNOME desktop to a new one. It will be interesting to see how that works.

It Snapped Clean Away - Replacing the Front Shocks On My Truck




Yesterday I decided to install new front shock absorbers on my rather elderly Ford truck. I've had the parts for a couple months, but decided I'd better get to it before Winter sets in.

Knowing the parts would be rusted, I sprayed them with WD-40 several times in the past week or two. This, in hopes some would penetrate and help the retaining nuts come loose when I removed them.

I started work on the passenger side. The nut on the top stud of the old shock was jammed on and wouldn't budge. Thinking I'd come back to it in a few minutes, I started work on the bottom stud. Within a minute or two,the bottom mounting nut came off all right - with the threaded end of the stud still stuck in it!! The rest of the stud was still attached to the truck and was holding the shock. [See above photo - bottom portion]I knew I was in trouble then - as the stud was a permanently attached part of the lower suspension arm. With the threaded portion broken off, there was no way to retain the bottom end of the new shock. After some proverbial head scratching, I went back in the house and got online to see how other folks handle this sort of problem. I quickly found out I was NOT alone - this problem is quite common. AND there is a reasonably inexpensive fix.

Fortunately, auto parts stores sell generic "Help" kits to replace broken shock mounting studs. Check places such as Autozone, NAPA, ... The new stud in the repair kit consists of a double-ended stud: the shock absorber mounts to the long, mostly smooth end; the short, slightly fatter threaded end goes into a hole in the frame or suspension member and mounts with a washer and nut. The old stud, of course, must be removed before the new one can be installed. Below I'll detail, in words and pictures, what I did.

Items needed:

New shock mounting stud repair kit - probably should get one for BOTH sides of the vehicle
hand-held "angle grinder" - preferably a 4.5" one. The wheel on a larger 5 or 6" one is too big and will be hitting stuff you don't want cut.
"Cut off" wheel and coarse grinding wheel for the grinder
an electric drill - preferably a 1/2" one
a set of drill bits - preferably titanium coated
A drill bit the right size for the new mounting stud in the repair kit you bought
Center punch and hammer

Here, in a nutshell, is what to do:

1) Use the angle grinder with "cut-off" wheel to remove the broken stud, cutting it off flush with the suspension or frame member it's attached to.
2) If necessary, use the angle grinder to cut through the top mounting stud on the shock absorber itself. That top stud is usually made of fairly mild steel, so one can cut partially through it and snap it off by pulling outward on the bottom end of the shock absorber. You may need to rock it back and forth a couple times, but it will break off with some effort. This is what I did, because the radius of the grinding wheel would have cut into stuff I didn't want damaged if I had gone clear through the stud. You will be working in tight quarters, so BE EXTREMELY CAREFUL to NOT cut the vehicle's coil spring or any other parts when using the grinder.

3) Use a center punch to mark dead center where the stud was.
4) Drill a hole where you made the punch mark. Start with a 1/8" drill and work up through your drill sizes to - in my case, a 1/2" hole - to accommodate the mounting stud. When drilling, coat the drill bit liberally with motor oil to help it cut.
5) On my vehicle, there was a 1/4" raised "shoulder" that was part of the old mounting stud - and was still on the lower suspension arm. I had to thin this down by 1/8" with the coarse wheel in the angle grinder so I could get the back mounting nut and washer fully threaded onto the new stud. Below is the picture of the hole drilled out and the shoulder ground down.
[Yes, I got the hole off center. Didn't start out that way, but I think the large drill bit "crept" out of the small pilot hole - I had to skip several drill sizes between my largest pilot drill and the final hole size. I also was drilling with a long bit at a really bad angle. At least there's enough shoulder metal remaining it shouldn't hurt anything. The rubber bushing on the new shock still has plenty of shoulder to bear against, so a washer wasn't necessary.]


6) Once the new stud is able to be nutted in place, you are ready to install the new shock. Below is the picture of the new shock installed.


Notes:
I got BOTH the shocks replaced within an hour and a half. The driver's side lower mounting stud did NOT break when I removed the nut, so all I had to do there is cut the top mounting stud on the shock and remove it as described in step 2 above.

Frankly, I expected the worst, given what immediately happened when I started the job. Thus I bought TWO repair kits so if the other one broke I'd have the parts right there.

My local auto supply store only had one lower shock mount repair kit in stock, but they were able to locate one in a neighboring area and get it held for me so I could drive over and get it.

I'm keeping my extra repair kit around in case I need it in the future.

I am eternally grateful to my neighbor for the use of his 4.5" angle grinder and 1/2" electric hand drill, as well as to several good folks on the Internet whose posts helped me deal with the problem at hand.