Weird multiple definition message

The most probable cause of this is that you’ve written your header file like

#ifndef SOME_HEADER_H_
#define SOME_HEADER_H_

#include <some_lib.h>
someType encSwitch;

#endif

Which is C++ code to create a global variable called encSwitch. Thus if you include that header from 2 separate .cpp files, both .cpp files are trying to create the same global variable – thus a multiple definition.

You’ll need to use extern someType encSwitch; in the header to only convey the information that this variable exists somewhere (declaration), and then only in one .cpp file instantiate the global variable with someType encSwitch (definition).

Refer e.g.

1 Like