Search code examples
ccompiler-constructionlinkerpicmplab-c18

Link step can't find symbols (XC8 compiler)


I'm trying to compile and link a C program using the XC8 compiler. I changed from the C18 compiler and made some minor compatibility changes to the code. With C18, the code compiled and linked just fine. With XC8, compiling goes fine, but the link step fails with this error:

Error [500] ; 0. undefined symbols:
_putch(server.obj) _ENC_Init(server.obj) _ENC_WriteRegister(server.obj) _ENC_ReadRegister(server.obj)

As the compiling succeeds, I guess there are prototypes found, ergo the .h files are included okay. I guess the compiler can't find the .c files.

The function putch is not called in my own program, but it's called in putchar and I use that function. The functions starting with ENC_ are my own functions.

I added two paths to the "Include search path" of the XC8 toolsuite:

  • C:\Program Files (x86)\Microchip\xc8\v1.12\sources, where the compiler's .c files are located, I believe
  • C:\...\lib, where my own .c files are located.

However, I still get the error.

How can I resolve this problem?

This is the full log:

Advisory[1233] Employing 18F4620 errata work-arounds:
Advisory[1234]  * Corrupted fast interrupt shadow registers
Advisory[1234]  * Data in RAM location can be corrupted if async. reset occurs during write
Warning [1273] ; . Omniscient Code Generation not available in Free mode
cgpic18 "--edf=C:\Program Files (x86)\Microchip\xc8\v1.12\dat\en_msgs.txt" --cmode=htc -Og9s -q -E1 -w9 -PMS0:code:0@CODE=00h-0FFFFh -PMS0:code:0@CONST=00h-0FFFFh -PMS0:code:0@SMALLCONST=01000h-010FFhx240 -PMS0:code:0@MEDIUMCONST=01000h-0FFFFh -PMS1:data:8@COMRAM=01h-07Fh -PMS1:data:0@ABS1=00h-0F7Fh -PMS1:data:0@BIGRAM=01h-0F7Fh -PMS1:data:0@RAM=080h-0FFh,0100h-01FFhx14,0F00h-0F7Fh -PMS1:data:400@BANK0=080h-0FFh -PMS1:data:800@BANK1=0100h-01FFh -PMS1:data:1000@BANK2=0200h-02FFh -PMS1:data:2000@BANK3=0300h-03FFh -PMS1:data:0@BANK4=0400h-04FFh -PMS1:data:0@BANK5=0500h-05FFh -PMS1:data:0@BANK6=0600h-06FFh -PMS1:data:0@BANK7=0700h-07FFh -PMS1:data:0@BANK8=0800h-08FFh -PMS1:data:0@BANK9=0900h-09FFh -PMS1:data:0@BANK10=0A00h-0AFFh -PMS1:data:0@BANK11=0B00h-0BFFh -PMS1:data:0@BANK12=0C00h-0CFFh -PMS1:data:0@BANK13=0D00h-0DFFh -PMS1:data:0@BANK14=0E00h-0EFFh -PMS1:data:0@BANK15=0F00h-0F7Fh -PMS1:data:0@SFR=0F80h-0FFFh -PMS3:config:0@CONFIG=0300000h-030000Dh -PMS2:eedata:0@EEDATA=0F00000h-0F003FFh -PMS4:idloc:0@IDLOC=0200000h-0200007h "--cfgdata=C:\Program Files (x86)\Microchip\xc8\v1.12\dat\cfgdata\18f4620.cfgdata" --cfgprefix=__CFG_ -MLFSROK -MIEEE_DBL -MIEEE_FLT -PPIC18F4620,1,65535,3967,8194,31,1,0,127,0 -fp -AC:\Users\...\AppData\Local\Temp\s234. --funcdat=C:\Users\...\AppData\Local\Temp\s234.5 --addrqual=ignore --runtime=init --runtime=clear server.p1 "C:\Program Files (x86)\Microchip\xc8\v1.12\lib\pic18-plib-htc-18f4620.lpp" "C:\Program Files (x86)\Microchip\xc8\v1.12\lib\pic18-stdlib-htc-d32-f32.lpp"
cgpic18 "--edf=C:\Program Files (x86)\Microchip\xc8\v1.12\dat\en_msgs.txt" --cmode=htc -q -E1 -Dserver.sdb -PMS0:code:0@CODE=00h-0FFFFh -PMS0:code:0@CONST=00h-0FFFFh -PMS0:code:0@SMALLCONST=01000h-010FFhx240 -PMS0:code:0@MEDIUMCONST=01000h-0FFFFh -PMS1:data:8@COMRAM=01h-07Fh -PMS1:data:0@ABS1=00h-0F7Fh -PMS1:data:0@BIGRAM=01h-0F7Fh -PMS1:data:0@RAM=080h-0FFh,0100h-01FFhx14,0F00h-0F7Fh -PMS1:data:400@BANK0=080h-0FFh -PMS1:data:800@BANK1=0100h-01FFh -PMS1:data:1000@BANK2=0200h-02FFh -PMS1:data:2000@BANK3=0300h-03FFh -PMS1:data:0@BANK4=0400h-04FFh -PMS1:data:0@BANK5=0500h-05FFh -PMS1:data:0@BANK6=0600h-06FFh -PMS1:data:0@BANK7=0700h-07FFh -PMS1:data:0@BANK8=0800h-08FFh -PMS1:data:0@BANK9=0900h-09FFh -PMS1:data:0@BANK10=0A00h-0AFFh -PMS1:data:0@BANK11=0B00h-0BFFh -PMS1:data:0@BANK12=0C00h-0CFFh -PMS1:data:0@BANK13=0D00h-0DFFh -PMS1:data:0@BANK14=0E00h-0EFFh -PMS1:data:0@BANK15=0F00h-0F7Fh -PMS1:data:0@SFR=0F80h-0FFFh -PMS3:config:0@CONFIG=0300000h-030000Dh -PMS2:eedata:0@EEDATA=0F00000h-0F003FFh -PMS4:idloc:0@IDLOC=0200000h-0200007h "--cfgdata=C:\Program Files (x86)\Microchip\xc8\v1.12\dat\cfgdata\18f4620.cfgdata" --cfgprefix=__CFG_ -MLFSROK -MIEEE_DBL -MIEEE_FLT -PPIC18F4620,1,65535,3967,8194,31,1,0,127,0 -AC:\Users\...\AppData\Local\Temp\s234. --funcdat=C:\Users\...\AppData\Local\Temp\s234.5 --addrqual=ignore --runtime=init --runtime=clear server.p1 "C:\Program Files (x86)\Microchip\xc8\v1.12\lib\pic18-plib-htc-18f4620.lpp" "C:\Program Files (x86)\Microchip\xc8\v1.12\lib\pic18-stdlib-htc-d32-f32.lpp"
aspic18 "--edf=C:\Program Files (x86)\Microchip\xc8\v1.12\dat\en_msgs.txt" --cmode=htc -E1 "-CC:\Program Files (x86)\Microchip\xc8\v1.12\dat\picc-18.ini" -ver=V1.12 -lserver.lst --opt= -n -18F4620 --comdiv=127 -no_pa -oserver.obj C:\Users\...\AppData\Local\Temp\s234.
aspic18 "--edf=C:\Program Files (x86)\Microchip\xc8\v1.12\dat\en_msgs.txt" --cmode=htc -E1 "-CC:\Program Files (x86)\Microchip\xc8\v1.12\dat\picc-18.ini" -ver=V1.12 --opt= -n -18F4620 --comdiv=127 -no_pa -oC:\Users\...\AppData\Local\Temp\s234.obj C:\Users\...\AppData\Local\Temp\s234.as
hlink "--edf=C:\Program Files (x86)\Microchip\xc8\v1.12\dat\en_msgs.txt" -cs -h+server.sym -z -w9 -Q18F4620 -Mserver.map -E1 -ver=XC8#PRO##V1.12 -ACODE=00h-0FFFFh -ACONST=00h-0FFFFh -ASMALLCONST=01000h-010FFhx240 -AMEDIUMCONST=01000h-0FFFFh -ACOMRAM=01h-07Fh -AABS1=00h-0F7Fh -ABIGRAM=01h-0F7Fh -ARAM=080h-0FFh,0100h-01FFhx14,0F00h-0F7Fh -ABANK0=080h-0FFh -ABANK1=0100h-01FFh -ABANK2=0200h-02FFh -ABANK3=0300h-03FFh -ABANK4=0400h-04FFh -ABANK5=0500h-05FFh -ABANK6=0600h-06FFh -ABANK7=0700h-07FFh -ABANK8=0800h-08FFh -ABANK9=0900h-09FFh -ABANK10=0A00h-0AFFh -ABANK11=0B00h-0BFFh -ABANK12=0C00h-0CFFh -ABANK13=0D00h-0DFFh -ABANK14=0E00h-0EFFh -ABANK15=0F00h-0F7Fh -ASFR=0F80h-0FFFh -preset_vec=00h,intcode,intcodelo,powerup,init,end_init -pramtop=01000h -psmallconst=SMALLCONST -pmediumconst=MEDIUMCONST -pconst=CONST -AFARRAM=00h-00h -ACONFIG=0300000h-030000Dh -pconfig=CONFIG -AIDLOC=0200000h-0200007h -pidloc=IDLOC -AEEDATA=0F00000h-0F003FFh -peeprom_data=EEDATA -prdata=COMRAM,nvrram=COMRError   [500] ; 0. undefined symbols:
_putch(server.obj) _ENC_Init(server.obj) _ENC_WriteRegister(server.obj) _ENC_ReadRegister(server.obj) 
AM,nvbit=COMRAM,rbss=COMRAM,rbit=COMRAM -pfarbss=FARRAM,fardata=FARRAM -pintsave_regs=BIGRAM,bigbss=BIGRAM,bigdata=BIGRAM -pbss=RAM -pidata=CODE,irdata=CODE,ibigdata=CODE,ifardata=CODE C:\Users\...\AppData\Local\Temp\s234.obj server.obj
del l.obj
del C:\Users\...\AppData\Local\Temp\s234.
del C:\Users\...\AppData\Local\Temp\s234.1
del C:\Users\...\AppData\Local\Temp\s234.2
del C:\Users\...\AppData\Local\Temp\s234.3
del C:\Users\...\AppData\Local\Temp\s234.4
del C:\Users\...\AppData\Local\Temp\s234.5
del C:\Users\...\AppData\Local\Temp\s234.as
del C:\Users\...\AppData\Local\Temp\s234.obj
(908) exit status = 1

Solution

  • Looking at a post here, and consulting the Microchp XC8 users manual it turns out that at least one problem is that your source is lacking a putch() function. Many routines (such as printf(), for instance) in the Microchip libraries rely on the presence of the putch() function for their operation, and this function must be supplied by you. Whereas on "regular" computers such a function would be expected to print a character to stdout, microcontrollers lack standard output, and therefore the putch() is relied on to in a sense "define" what your "standard" output is. The putch() function is supposed to output a single character to some output such as LCD, serial, blinking LED? (in Morse code perhaps?), or carrier pigeon. From the manual, page 350:

    The printf() function is a formatted output routine, operating on stdout. It relies on the putch() function to determine the destination of stdout. The putch() function must be written as part of each project, as well as code to initialize any peripherals used by this routine. A stub for putch can be found in the sources directory of the compiler.

    Writing the putch() function, even one that does nothing, will solve at least the issue of _putch being undefined: it appears that _putch (the name of the function in the error) is just a a name-mangled putch().