What does it mean when I receive a multiple definition compiler error, followed by a "link terminated due to previous error(s)"?

First, you need to know what a translation unit includes. A compiler translation unit is a C/C++ file and all of the include files. What this error means is that a function or variable is defined multiple times across different translation units (one way or another). Although many users know how to put function prototypes and variable typedefs within guarded headers, there is often a misunderstanding about what the guard is capable of doing within the header file. For example:

Even with the guards in place, myfile.h is included in both Foo.c and Bar.c. They are independent compilations. The guards only prevents you from including myfile.h more than once in Foo.c.

If you are experiencing errors, you may have:

  • missing externs,
  • missing typedefs,
  • or missing guards definitions (that should not be in a header file).

An example of what one might report follows:

© 2018 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.