c - EXPORT_SYMBOL in header causes "exported twice" errors -
i have header file declaration of several global variables in following format:
constants.h
#ifndef constants_h #define constants_h extern unsigned var; export_symbol(var); #endif
constants.c
#include "constants.h" unsigned var = 10;
foo.c
#include "constants.h"
when try compile kernel module, following error each respective exported symbol:
warning: /home/vilhelm/proj/constants: 'var' exported twice. previous export in /home/vilhelm/proj/foo.ko
i suspect symbols being exported every time include constants.h header file, don't understand why. shouldn't include guard in constants.h prevent export_symbol(var)
being read multiple times?
shouldn't include guard in constants.h prevent export_symbol(var) being read multiple times?
the include guard prevents header being included more once in same source file. can't prevent being included via multiple source files. remember objects sources linked single object, , hence conflict.
let's have header included in source files, called foo.h, in turn includes constants.h. file constants.c try include constants.h twice (once directly via constants.h , again via foo.h). include guard works here, , constants.h included once.
same thing happen foo.c. try include constants.h twice (once directly via constants.h , again via foo.h). include guard works here too, , constants.h included once.
but 2 objects, constants.o , foo.o linked together, each single copy of export via constants.h. adds two.
you want make sure exports appear in final link once. 1 way take them out of common file constants.h, , move them file called exports.c.
Comments
Post a Comment