Search code examples
clinuxgcclinkermultiple-definition-error

gcc __attribute__((selectany)) alternative for linux?


i would like to know if there is an alternative for __attribute__((selectany)) in linux ?

i would like to define something like that:

char * a[] = { "qwe", "zxc" };

in a header file and include it in many .c files which would be linked together. so the linker will see more than one definition of "a" and therefor will not link. i've read of this attribute (selectany), which will use only the first seen definition of "a", unfortunately it is only for ms windows. so the question is: is there an alternative method in linux ?

edit: the actual question is: is there a way to instruct the linker to use only the first seen definition and ignore any other perhaps even if they are different ? i know there are many ways to define my data, i'm not searching for solution of how to define my data, instead i would like to know if there is a way to have multiple definitions and make the linker work with the first seen...


Solution

  • I think you are looking for the 'weak' gcc attribute.