3

I'm using gcc, and I am distributing an object file which may be used in conjunction with some third party code. I have something that looks like this:

void fn3rdParty(int bar) __attribute ((weak));

void fn(void) {
    if(fn3rdParty)
        fn3rdParty(SOME_ENUM);
}

where SOME_ENUM is an enum and is defined by the third party code if present. I tried declaring SOME_ENUM as a weak int, but gcc complains that the type is redefined. I'm wondering if there's a way around this? (I'd like to avoid having one .o file for use with this software, and another to be used without).

John

John
  • 3,400
  • 3
  • 31
  • 47
  • 3
    enums replaced by numbers during compilation (`int`s, if not specified otherwise). `.o` cannot contain enum. Are you missing header file with enums definitions? – keltar Mar 24 '14 at 16:29
  • Ahh... so the enum is not treated as an external symbol... that's unfortunate, as it will cause problems if trying to link against different versions of the 3rd party software. I'll discuss with the 3rd party and maybe move these to ints. Thanks – John Mar 24 '14 at 17:58
  • Enums are ints under the hood. If someone changes the enum definition and recompile one library but wouldn't recompile the other - bad things will happen. But i don't see your problem, what prevents you from just using enums when you need them? – keltar Mar 24 '14 at 18:02
  • Or am I misunderstanding and `SOME_ENUM` is actually enum-typed (global?) variable and not enumeration constant? – keltar Mar 24 '14 at 18:09
  • For background on the problem: some people get the .o file, and some get the .c file. If they get the .c file, and not the third party software, this still has to build. On top of this, I hadn't considered the fact that enums were constants, and wouldn't work against different versions of the third party software, which is another problem I'll have to address. – John Mar 24 '14 at 18:18
  • And you want this `.o` to be identical to what your users could compile themselves? Or `ifdef`s would suffice? If not, perhaps your third party could bring their enums into separate header file and distribute it under permissive license (not their code, just a header) - that should be more than enough. – keltar Mar 24 '14 at 18:23

0 Answers0