Compiling C Source Code Files

Now compile the start08.c file.

  1. Select File > Compile from the HC08 Compiler menu bar.

    The Select File to Compile dialog box appears.

    Figure 1. Select File to Compile Dialog Box

    Select File to Compile Dialog Box

  2. Browse to the Project_settings\Startup_Code folder in the project directory.
  3. Select the start08.c file.
  4. Click Open.

    The start08.c file begins compiling, as shown in the following figure. In this case, the file fails to compile.

    Figure 2. Results of Compiling start08.c File

    Results of Compiling start08.c File

    The HC08 Compiler window provides information about the compilation process, and generates the error messages if the compilation fails. In this case, the C5200: `FileName' file not found error message appears twice, once for start08.h and once for non_bank.sgm.

  5. Right-click the text above the error message.

    A context menu appears.

    Figure 3. HC08 Compiler Window - Context Menu

    HC08 Compiler Window - Context Menu

  6. Select Help on "<FileName> file not found" from the context menu.

    The C5200: `FileName' file not found error message appears.

    Figure 4. C5200 Error Message Help

    C5200 Error Message Help

    The Tips section in the help for the C5200 error states that the correct paths and names for the source files must be specified. The following folder contains both the missing files, start08.h and non_bank.sgm:

    <CWInstallDir>\MCU\lib\hc08c\include

    Note: The #include preprocessor directive for the start08.h file and the non_bank.sgm file appears on line 21 and 31 of the start08.c file, respectively.

To resolve the error, modify the compiler configuration so that it can locate the missing files.

  1. Select File > Configuration from the HC08 Compiler menu bar.

    The Configuration dialog box appears.

  2. Select the Environment tab in the Configuration dialog box.
  3. Select Header File Path and click [...] button.

    The Browse for Folder dialog box appears.

    Note: The environment variable associated with the Header File Path is the LIBPATH or LIBRARYPATH: `include <File>' Path variable. The Compiler uses a hierarchy to search for files. Refer to the File Processing.
  4. In the Browse for Folder dialog box, navigate to the missing start08.h file in the <CWInstallDir>\MCU\lib\hc08c\include folder, where CWInstallDir is the directory in which the CodeWarrior software is installed.
    Figure 5. include Subfolder Containing start08.h and non_bank.sgm Files

    include Subfolder Containing start08.h and non_bank.sgm Files

  5. Click OK.
  6. Click Add.

    The specified path appears in the lower panel.

  7. Click OK.

    An asterisk ( * ) now appears in the HC08 Compiler window's title bar, indicating that the configuration file contains unsaved changes.

  8. Click Save on the toolbar to save the configuration modifications. Alternatively, select File > Save Configuration from the HC08 Compiler menu bar.
    Note: If you do not save the configuration, the compiler reverts to the last-saved configuration when the program is relaunched. The asterisk ( * ) disappears when the file is saved.

Now that you have specified the paths to the missing files, you can try again to compile the start08.c file.

  1. Select File > Compile from the HC08 Compiler menu bar.
  2. Navigate to the Project_settings\Startup_Code folder in the project directory.
  3. Select start08.c.
  4. Click Open.

The HC08 Compiler window indicates successful compilation of the start08.c file and displays following results:

Now compile the main.c file:

  1. Select File > Compile from the HC08 Compiler menu bar.
  2. Navigate to the Sources folder.
  3. Select the main.c file.
  4. Click Open.

The C source code file, main.c, fails to compile, as the compiler can locate only three of the four header files required. It could not find the derivative.h header file and generates another C5200 error message.

The derivative.h file is in the Project_Headers folder in the X15 project folder, so add another header path to resolve the error.

  1. Select File > Configuration from the HC08 Compiler menu bar.

    The Configuration dialog box appears.

  2. Select the Environment tab in the Configuration dialog box.
  3. Select Header File Path and click the [...] button.

    The Browse for Folder dialog box appears.

  4. In the Browse for Folder dialog box, navigate and select the Project_Headers folder.
  5. Click OK.

    The Browse for Folder dialog box closes.

  6. Click Add.

    The selected path appears in the lower panel.

  7. Click OK.

    If there is no other missing header file included in the derivative.h file, you are ready to compile the main.c file.

  8. Select File > Compile from the HC08 Compiler window menu bar.
  9. Select main.c in the Sources folder. You can also select a previously compiled C source code file.
  10. Click Open to compile the file.

    The message "*** 0 error(s)," indicates that main.c compiles without errors. Save the changes in the project configuration.

The compiler places the object file in the Sources folder, and generates output listing files in the project folder. The binary object files and the input modules have identical names except for the extension used. Any assembly output files generated for each C source code file is similarly named.

Figure 6. Project Directory after Successful Compilation

Project Directory after Successful Compilation

At this time, only two of the three C source code files have been compiled. Locate the remaining C source code file, MC9S08GT32.c, in the Lib folder of the current directory, X15.

The compiler places the object-code files it generates in the same folder that contains the C source code files. However, you can also specify a different location for the object-code files.

To redirect the object-code file for the MC9S08GT32.c file to another folder, modify the compiler configuration so that when the MC9S08GT32.c file is compiled, the object code file goes into a different folder. For more information, refer to the OBJPATH: Object File Path).

  1. Using Windows Explorer, create a new folder in the current directory and name it ObjectCode.
  2. Select File > Configuration from the HC08 Compiler menu bar.
  3. Select the Environment tab and select Object Path.
  4. Click Browse.

    The Browse for Folder dialog box appears.

  5. In the Browse for Folder dialog box, browse for and select the ObjectCode folder.
  6. Click OK.

    The Browse for Folder dialog box closes.

  7. Click Add.

    The new object path appears in the lower pane.

    Figure 7. Adding OBJPATH

    Adding OBJPATH

  8. Click OK.

    The Configuration dialog box closes.

  9. Press Ctrl + S to save the settings.
  10. Select File > Compile from the HC08 Compiler menu bar.

    The Select File to Compile dialog box appears.

  11. Browse for the C source code file in the Lib subfolder of the project folder.
    Figure 8. Compiling Source File in Lib Folder

    Compiling Source File in Lib Folder

  12. Click Open.

    The selected file compiles.

    Figure 9. Successful Compilation of File in Lib Folder

    Successful Compilation of File in Lib Folder

The Compiler log states that the object code file, MC9S08GT32.o, is created in the ObjectCode folder, as specified. Save the project configuration again in case you wish to recompile any of the C source code files in future.

Tip: Move the other two object code files to the ObjectCode folder so that all object code files for the project are in the same place. This makes project management easier.

The haphazard builds of this project are intentionally designed to illustrate what happens if paths are not configured properly while compiling a project using the Compiler tool. The header files may be included by either C source or other header files. The lib folder in the CodeWarrior installation directory contains derivative-specific header and other files for Microcontrollers projects.

When you build another project with the Build Tool Utilities, make sure that the settings for the input and output files are done in advance.

Now that the project's object code files are available, you can use the linker build tool, linker.exe, together with an appropriate *.prm file, to link these object-code files with the library files and create an *.abs executable output file.

Refer to the Linker section in the Build Tool Utilities Manual for details. However, the project set up and configuration is faster and easier using the New Bareboard Project wizard.