20.5 Correcting compiler and linker errors


What if nothing seems to happen when you try to build and run your version of the Pop program? First make sure you can see the Output window, which is where your compiler errors are listed. If you can't find it, use a Windows Other Windows Output to open it [ Windows Output (Version 6.0)].

Then resize the Output window so you can see what's in there. Double-clicking on a compiler error will call up the Source-Code window with the cursor on the line where the error is. Locate the erroneous line and see if there's an obvious typo.

If not, go back and look at the error message. Read all of the error message. Think about what it says. Believe it or not, the message is trying to help you. In its own way, it's saying 'try this,' and not just, 'you're wrong.' If the message doesn't make sense to you, click on the error message and press F1 to get information about it.

Go back to the Source-Code window and look at the line with the error again. If you're unsure about the usage of any of the API functions there, highlight them and press F1 to get their documentation.

One thing that happens sometimes is that an error early in a code module causes a cascade of many more error messages further down. Generally, you should start trying to fix the errors from the beginning. If you fix a few errors and get to errors that don't seem to make sense, try to rebuild the program and/or recompile the module and see if some of them go away.

If you have an error that refuses to go away, skip over it and fix some of the later errors if you can. Maybe while you're working your subconscious will figure out what was wrong up above.

Let's repeat the key teaching we have to impart here:

When fixing an error, READ the error message and THINK ABOUT what it says.

One tends to not want to read an error message, as it's bad news, but this is a mistake. The message is trying to help you! An error message is not your enemy, it's your friend. It's trying to save you from your own mistakes!

If you get a zillion error messages saying things aren't found, that means there are some files missing from your project file or from the directory where your project lives. Not being able to find windows.h , for instance makes a lot of errors. You may need to check that the directory setting is correct.

Sometimes when working in a lab with the compiler on a remote server, your machine can't find the place on the server where the standard include files live. This may be what's going on if you get the zillion 'file not found' messages.

Microsoft Visual Studio keeps the information about which directories it searches on the Tools Options... Projects VC++ Directories sheet [this is the Tools Options... Directories sheet in Version 6.0]. These settings are not part of your project file, they are part of the individual compiler installation. The all-important Include directories setting is found by selecting Include Files in the Show Directories for combo box on this sheet. Make sure that one of the selections here corresponds to where your compiler has its include subdirectory. If you are working in a lab, your compiler may be on a remote drive with a funny letter name like K: or M:. You can use Windows Explorer to go out across the network and find where the Visual Studio Include directory lives.

Even if you have the directories right, you will get a 'not found' linker error if there is some function you prototyped but forgot to add the code for. Look at the error closely to figure out which function is missing. The function name will be in a 'mangled' format, so it can be a little hard to decipher.

Once in a while Visual Studio will get confused or lose track of what you've been doing, and even though you have properly defined all of your functions, it will say that it can't find one of them. This can happen if for some reason Visual Studio doesn't realize that it needs to recompile some files. The way to fix this situation is to use the Build Rebuild All option to force a rebuild of all files.

Invoking Build Rebuild All can also help if Visual Studio seems unable to find a resource that you're fairly sure you've put in place. If the rebuild doesn't fix things, then the problem is probably you; that is, you need to recheck what you think you've done.



Software Engineering and Computer Games
Software Engineering and Computer Games
ISBN: B00406LVDU
EAN: N/A
Year: 2002
Pages: 272

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net