C++ Function in Header throws Linker “already defined” Errors

If you define a function in the global namespace in a C++ header file and encounter linker errors (complaining about the function already defined elsewhere), there’s a simple fix! Simply mark the function as inline. This will prevent the duplication of the function in other source files.

Note that using inclusion guards does not solve this problem and you must define the function as inline.

Leave a Reply

Your email address will not be published.