RandyGaul / cute_headers

Collection of cross-platform one-file C/C++ libraries with no dependencies, primarily used for games
4.29k stars 267 forks source link

Error: "multiple definition of (function)" when including in .h file #275

Closed Pandaii closed 2 years ago

Pandaii commented 2 years ago

Hello, Whenever I try to include "cute_c2.h" in the header file of my GameField class, I get plenty of errors of the type: "multiple definition of (function)". The error happens each time the header of GameField.h is included in another file of my cpp program. I have used the recommended include method:

define CUTE_C2_IMPLEMENTATION

include "cute_c2.h"

The error does not happen when cute_c2.h is introduced in GameField.h instead of GameField.cpp.

Can you explain what happens please?

RandyGaul commented 2 years ago

It means you included the header with symbols defined into more than one C or CPP file.

You should only put the define and include after the define in one C or CPP file. For all other times simply include the header without the define. The define pastes in function definitions.