I am modifying the linux kernel for a device locally and I added a header file, say a.h inside /include/linux and referenced it in two C files inside the kernel directory. The header file contains a structure which has been initialised there itself. Whenever I compile the kernel, it shows me a multiple definition of 'struct_var' error. What changes should I make?
You need to ensure that it is only included once.
Typically, you would use
#ifndef UNIQUE_IDENTIFIER_MAYBE_THE_FILENAME #define UNIQUE_IDENTIFIER_MAYBE_THE_FILENAME // your file contents go here #endif
That way, the second time the compiler includes this file, UNIQUE_IDENTIFIER_MAYBE_THE_FILENAME is defined, so it does not define any of the bits inside.