Keil Logo

LX51: Linking User-Modified C Functions


Information in this article applies to:

  • C166 All Versions
  • C251 All Versions
  • C51 All Versions

QUESTION

I noticed that the putchar function is pulled out of the Keil Libraries. I would rather use my own version of putchar, instead of the one in the libraries.

How do I link my own version of the putchar function using µVision?

ANSWER

This answer pertains to all of the source files in C:\Keil\Cxx\Lib\, not just the PUTCHAR.C source file. To link your own version of a function (putchar, for example):

  1. Copy the PUTCHAR.C source file from the C:\Keil\Cxx\Lib\ directory into your project directory. The project directory is the folder where the .uv2 file for your project is located.

    Warning

    • Do not modify the source files in C:\Keil\Cxx\Lib\. These files are overwritten during µVision upgrade process, and any changes to them will be lost.
  2. Add the copied version of PUTCHAR.C (now in your project directory) to your project window and make your modifications.
  3. Compile and link your project.

If you open your MAP file, you will see:

...
MEMORY MODEL: SMALL


INPUT MODULES INCLUDED:.\PUTCHAR.obj (PUTCHAR)

This shows that the putchar being used by your project is the one located in the project directory. If you remove putchar.c from the project window and recompile, the map file would show the following:

\KEIL\Cxx\LIB\CxxS.LIB (PUTCHAR)

This shows that putchar is once again being called from the library.

The linker resolves external references using the project's object files first, then searches the C:\Keil\Cxx\Lib libraries for any other unresolved references. You must use the same name as the module you are trying to replace for this to automaticly happen. For example if you changed the name of the function in putchar.c to 'modified_putchar', the linker will use the putchar from the library, and ignore your modified putchar.c.

You can use the same procedure with non-Keil libraries. If you can, create a C file and include a function that has the same name as a module in the library. The compiler will look at the local directory, and use your version of the module, rather than the one in the library.

SEE ALSO


Last Reviewed: Thursday, February 25, 2021


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.