Search code examples
embeddedmplabxc8

MPLAB X XC8 Error: (500) Undefined Symbols


Im using MPLAB X v5.25 and XC8 v2.10

When building my code, I encounter an error that says error: (500) Undefined symbols and enumerates certain functions that are contained in other C files linked with headers.

*:0:: error: (500) undefined symbols:
    _OneWireTemp(dist/default/production\firstpic.X.production.o)
    _sending(dist/default/production\firstpic.X.production.o)
    _USART_Init(dist/default/production\firstpic.X.production.o) 
(908) exit status = 1*

The functions are from the one wire library, HTTP GPRS library and USART library.

Any help would be appreciated


Solution

  • [...] other C files linked with headers. [...]

    Header files do not link C files - they simply declare symbols. You get undefined symbols when the linker cannot match the symbols referenced in the code it has been asked to link. The most likely cause being that you have not actually linked the object code for each C file that the compiler compiled.

    That is to say, each C file must be separately compiled to create an object file. The purpose of the headers in this process is to make visible to the compiler the symbols that will be defined in separate object files.

    The object files generated by separate compilation are then passed to the linker which resolves the external references in one object file with definitions provided in other object files (or static libraries included in the link).

    It is the linker that is issuing the undefined symbols diagnostic, almost certainly because you have not separately compiled the C files and passed the generated object code to the linker.

    In most IDEs (and I don't believe MPLAB X is any different), you add the C source files to a "project", and the IDE's project manager will manage the separate compilation and linking for you. So it is likely that you have simply omitted to add the C sources to your project. No amount of header file inclusion is going to solve this issue, header files are included by the pre-processor (before compilation and linking).