I am trying to use the C8051 uart in a C program to talk to an AT modem device. To do this I need to work around the Keil library getchar which echoes received characters. So I made my own getchar function thinking this would override the library function. However, I am still using the stdio.h library because of all the other serial functions it has which build on this. When I try to build this project I get the following slew of linker warning messages. *** WARNING L7: MODULE NAME NOT UNIQUE MODULE: C:\KEIL\C51\LIB\C51S.LIB (GETCHAR) *** WARNING L1: UNRESOLVED EXTERNAL SYMBOL SYMBOL: ?C?CHARLOADED MODULE: C:\KEIL\C51\LIB\C51S.LIB (UNGETC) *** WARNING L1: UNRESOLVED EXTERNAL SYMBOL SYMBOL: ?_UNGETCHAR?BYTE MODULE: C:\KEIL\C51\LIB\C51S.LIB (UNGETC) *** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL SYMBOL: ?_UNGETCHAR?BYTE MODULE: C:\KEIL\C51\LIB\C51S.LIB (UNGETC) ADDRESS: 103CH *** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL SYMBOL: ?C?CHARLOADED MODULE: C:\KEIL\C51\LIB\C51S.LIB (UNGETC) ADDRESS: 103EH My concern is wether the other library functions (ie scanf, printf, gets, puts, etc) will work with my customized overriding getchar. The first warning message makes me wonder about this. The remainder I take it are because I do not have ungetchar support written into my getchar function (do I need to in order to use scanf and the like?). (note - I have looked at the following support page... http://www.keil.com/support/docs/1791.htm ...and this is actually exactly what I am already doing which is giving me this concern)
You need to redefine ungetchar() as well as getchar() to prevent the linker having a fit. Your warning messages will then disappear.
You also need to ensure that your version exactly matches the standard prototype - same name, same return type, same parameters.
thanks all... this hits the nail on the head, although without support for ungetchar I found that printf and scanf and the like will not function properly. simply adding support for one char ungotten fixed this. it does seem rather bizzare, however, that Keil does not provide a compiler/linker switch to shut echoes off.
"it does seem rather bizzare, however, that Keil does not provide a compiler/linker switch to shut echoes off." It's not at all bizarre, because it is not a function of either the compiler or the linker! Keil provides the source code for these functions to that you can see what it does, and modify it to your requirements, if necessary.
Read the manual. No workaround is required. copy Putchar.c for the lib folder to your project. add it to your project (or make file). comment out the echo in your copy. printf() ect will now link you the local copy.
"Read the manual." Read the thread.