Microchip Technology SW006021-2 Manuale Utente
MPLAB
®
XC8 C Compiler User’s Guide
DS52053B-page 82
2012 Microchip Technology Inc.
4.4.1.2
USER-DEFINED LIBRARIES
User-defined libraries may be created and linked in with programs as required. Library
files are more easy to manage and may result in faster compilation times, but must be
compatible with the target device and options for a particular project. Several versions
of a library may need to be created to allow it to be used for different projects.
files are more easy to manage and may result in faster compilation times, but must be
compatible with the target device and options for a particular project. Several versions
of a library may need to be created to allow it to be used for different projects.
Libraries can be created manually using the compiler and the librarian, LIBR. See
Section 8.2 “Librarian” for more information on the librarian and creating library files
using this application. Alternatively, library files can be created directly from the
compiler by specifying a library output using the --OUTPUT option, see
Section 4.8.44 “--OUTPUT= type: Specify Output File Type”.
Section 8.2 “Librarian” for more information on the librarian and creating library files
using this application. Alternatively, library files can be created directly from the
compiler by specifying a library output using the --OUTPUT option, see
Section 4.8.44 “--OUTPUT= type: Specify Output File Type”.
User-created libraries that should be searched when building a project can be listed on
the command line along with the source files.
the command line along with the source files.
As with Standard C library functions, any functions contained in user-defined libraries
should have a declaration added to a header file. It is common practice to create one
or more header files that are packaged with the library file. These header files can then
be included into source code when required.
should have a declaration added to a header file. It is common practice to create one
or more header files that are packaged with the library file. These header files can then
be included into source code when required.
Library files specified on the command line are scanned first for unresolved symbols,
so these files may redefine anything that is defined in the C standard libraries. See also
Section 5.15.4 “Replacing Library Modules”.
so these files may redefine anything that is defined in the C standard libraries. See also
Section 5.15.4 “Replacing Library Modules”.
4.4.2
Startup and Initialization
A C program requires certain objects to be initialized and the device to be in a particular
state before it can begin execution of its function main. It is the job of the runtime
startup code to perform these tasks. Section 5.10.1 “Runtime Startup Code” details
specifically what actions are taken by this code and how it interacts with programs you
write.
state before it can begin execution of its function main. It is the job of the runtime
startup code to perform these tasks. Section 5.10.1 “Runtime Startup Code” details
specifically what actions are taken by this code and how it interacts with programs you
write.
Rather than the traditional method of linking in a generic, precompiled routine, the
MPLAB XC8 C Compiler determines what runtime startup code is required from the
user’s program and then generates this code each time you build.
MPLAB XC8 C Compiler determines what runtime startup code is required from the
user’s program and then generates this code each time you build.
Both the driver and code generator are involved in generating the runtime startup code.
The driver creates the code which handles device setup and this code is placed into a
separate assembly startup module. The code generator produces code which initial-
izes the C environment, such as clearing uninitialized C variables and copying
initialized C variables. This code is output along with the rest of the C program.
The driver creates the code which handles device setup and this code is placed into a
separate assembly startup module. The code generator produces code which initial-
izes the C environment, such as clearing uninitialized C variables and copying
initialized C variables. This code is output along with the rest of the C program.
The runtime startup code is regenerated every time you build a project. The file created
by the driver may be deleted after compilation, and this operation can be controlled with
the keep suboption to the --RUNTIME option. The default operation of the driver is to
keep the startup module; however, if using MPLAB IDE to build, file will be deleted
unless you indicate otherwise in the Project Properties dialog, see.
by the driver may be deleted after compilation, and this operation can be controlled with
the keep suboption to the --RUNTIME option. The default operation of the driver is to
keep the startup module; however, if using MPLAB IDE to build, file will be deleted
unless you indicate otherwise in the Project Properties dialog, see.
If the startup module is kept, it will be called startup.as and will be located in the
current working directory. If you are using an IDE to perform the compilation the
destination directory may be dictated by the IDE itself. MPLAB X IDE store this file in
the dist/default/production directory in your project directory.
current working directory. If you are using an IDE to perform the compilation the
destination directory may be dictated by the IDE itself. MPLAB X IDE store this file in
the dist/default/production directory in your project directory.