Compiling C Source Code Files

Now compile the start08.c file.

  1. Select File > Compile from the RS08 Compiler window 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. In this case, the file fails to compile.

    Figure 2. Results of Compiling start08.c File
    Results of Compiling start08.c File

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

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

    A context menu appears.

    Figure 3. RS08 Compiler Window - Context Menu
    RS08 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 f or the C5200 error states that the correct paths and names for the source files must be specified.

The following folder contains the missing header file, startrs08.h:

  <CWInstallDir>
  \
  MCU\lib\rs08c\include 
  
Note: The #include preprocessor directive for this header file appears on line 29 of start08.c.

The following folder contains the missing startrs08_init.c file.

CWInstallDir\MCU\lib\rs08c\src

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

  1. Select File > Configuration from the RS08 Compiler window menu bar..

    The Configuration dialog box appears.

  2. Select the Environment tab in the Configuration dialog box.
  3. Select Header File Path.
    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 ( File Processing).
  4. Click "..." button.

    The Browse for Folder dialog box appears.

  5. In the Browse for Folder dialog box, navigate to the missing startrs08.h file in the <CWInstallDir>\MCU\lib\rs08c\include folder.
    Figure 5. include Subfolder Containing startrs08.h
    include Subfolder Containing startrs08.h
  6. Click OK.

    The Configuration dialog box is now active.

  7. Click the Add button.

    The specified path appears in the lower panel.

  8. Click " ... " button again.
  9. In the Browse for Folder dialog, navigate to \lib\hc08c\include subfolder in the CodeWarrior installation folder.
  10. Click Add.

    The path to the header files <CWInstallDir>\MCU\lib\hc08c\include appears in the lower pane.

  11. Select General Path.
  12. Click " ... " button.
  13. In the Browse for Folder dialog, navigate to the missing startrs08_init.c file in the rs08c\src subfolder in the CodeWarrior installation's lib folder.
  14. Click Add.

    The path to the header files < CWInstallDir>\MCU\lib\rs08c\src appears in the lower panel.

  15. Click OK.

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

  16. Click Save on the toolbar to save the configuration modifications. Alternatively, select File > Save Configuration from the RS08 Compiler window menu bar.

You have now saved the new paths to the missing files to compile the start08.c file.

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 supplied the paths to the missing files, you can try again to compile the start08.c file.

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

The Compiler indicates successful compilation for the start08.c file.

The compiler displays following results:

Now compile the main.c file:

  1. Navigate to the Sources folder.
  2. Select the main.c file.
  3. 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 generated 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 RS08 compiler window menu bar.

    The Configuration dialog box appears.

  2. Select the Environment tab.
  3. Select Header File Path.
  4. Click " ... " button.

    The Browse for Folder dialog box appears.

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

    The Browse for Folder dialog box closes.

  7. Click Add.

    The selected path appears the lower pane.

  8. 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.

  9. Select File > Compile from the RS08 Compiler window menu bar.
  10. Select main.c in the Sources folder. You can also select a previously compiled C source code file.
  11. 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 along with the C source code file, and generates output listing files into 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.

At this time, only two of the three C source code files have been compiled. Locate the remaining C source code file, MC9RS08KA1.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 MC9RS08KA1.c file to another folder, modify the compiler configuration so that when the MC9RS08KA1.c 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.
  3. Click the Environment tab and select Object Path.
  4. Navigate to the new object code folder, ObjectCode, in the project folder.
  5. Click OK.
    Figure 6. Adding OBJPATH
    Adding OBJPATH
  6. Click Add.

    The new object path appears in the lower panel.

  7. Click OK.

    The Configuration dialog box closes.

  8. Press Ctrl + S to save the settings.
  9. Select File > Compile from the RS08 Compiler window menu bar.

    The Select File to Compile dialog box appears.

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

The selected file compiles.

The compiler log states that MC9RS08KA1.o, the object code file, was created in the ObjectCode folder, as specified. Save the configuration again in case you wish to recompile any of the C source code files in the 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 properly configured 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 contains many derivative-specific header and other files available for inclusion into your 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.

For more information, refer to the Linker section in the Build Tool UtilitiesManual. However, the project set up and configuration is faster and easier using the New Bareboard Project wizard.