Building code fail

I have following problem when building that code. I call a function (not a class member) from
a library i work on.

See yellow messages/errors. Multiple definition of "preamble".

I see that there are many messages for multiple defs of variables, but I can’t find multiple defs:

Please share here the source code of lib/sACN/sACN.h. Looks like you include this file many times in the different places .

Hi @sstaub!

You are using sACN.h in two files: main.cpp and sACN.cpp thus each of them has its own copy of global variables from sACN.h after preprocessing. A small explanation:

(a) int some_var;
(b) int some_var = 13;

(a) Each file that includes the header creates a tentative definition of the variable.
(b) Only one source file can use the header.

Probably the best way to avoid such errors is to use extern in header file declaration and define a variable in each source file. An example:


extern int var;


#include "file.h"
int var = 135;


#include "file.h"
int main ()
   var = 0;

A comprehensive post about this topic on the stackoverflow.
I hope the information above will be helpful.

Thank you very much for the informations, they are very helpful.
I found a temporary solution for the problem, I changed in main.cpp
the #include sACN.h with #include sACN.cpp. Now it works, until
I implement a better solution.