Installing getopt

Getopt.h is a header in the GNU standard library that contains utilities for extracting arguments from the command line for text-based C/C++ applications. Because getopt.h is not part of the ANSI C standard library, getopt must be built into each project that uses it, or compiled it into a static library and linked to explicitly. A precompiled version of getopt is available, so you will be copying the .h and the .lib files to your computer, then adding these directories to the VC++ search paths so that getopt can be used as if it were part of the standard library.

Note: Every homework project is configured to explicitly pass getoptd.lib to the linker. If you need to create your own project instead of using the pre-configured ones, make sure that you specify getoptd.lib as an input to the linker.

Note for users upgrading from VC++ 2005: If you uninstalled VC++ 2005, you will need to download getopt9, which was built with VC++ 2008. The version of getopt offered fall 07, which is now called getopt8, was built with VC++ 2005 and linked to version 8 of the Microsoft CRT (C Run-Time). If you try running an application that depends on version 8 of the crt without the necessary dlls (msvcr80.dll and msvcr80d.dll), the application will fail to start and you will get a "side by side configuration error." If you receive this message after linking to getopt8 from VC++ 2008, there are several possible solutions:

  1. Download getopt9.zip and extract to C:\Program Files\

    To extract a zip file in Windows XP or Vista, right click on the file and click Extract All.
  2. Open VC++ by going to Start -> Programs -> Visual C++ 9.0 Express Edition -> Microsoft Visual Studio 2008 Express Edition.

    Go to Tools -> Options.
  3. 10. In the left tree, expand Projects and Solutions -> VC++ Directories.

    In the Show directories for: dropdown, select Include files.

    Add C:\Program Files\getopt9\include to the end of the list. You can add an item to the list by clicking the folder icon on the upper right or by clicking on the white space below the last item in the list.

    If the compiler cannot find C:\Program Files\getopt9\include\getopt.h, your homework assignments will not compile!
  4. In the Show directories for: dropdown, select Library files.

    Add C:\Program Files\getopt9\lib to the end of the list.

    If the linker cannot find C:\Program Files\getopt9\lib\getoptd.lib, your homework assignments will fail to link!
  5. In the left tree, select Build and Run. In the MSBuild project build output verbosity dropdown and select Detailed.
  6. In the left tree, expand Text editor -> C/C++ -> Tabs. Select Insert spaces and click OK.