Zamaster wrote:Thanks guys, I had most of that but St_W's solution to use FB_MAIN is close to what I needed. Unfortunately this requires that the code is included at least once in the main module. Is there a way to do it so that its included in exactly ONE of the modules even if not included in FB_MAIN?
Summary: As the modules are compiled separately I see no way to automatically implement the methods in one of the modules. Just implement the methods explicitly in one of the modules.
Attempt of an explanation:
I guess you are referring to the C++-way of using templates. Unfortunately I don't know a lot about C++, so I'll try explain in a more general manner.
The problem with templates is that in theory the number of possible types for whose the template could be instantiated is infinitely large. And this problem does matter because the compiler does not know the types in all different modules - just of the one it is compiling at a time.
There are (at least) two solutions for this problem:
1. Explicitly tell the compiler which types can be used for template instantiation, so that the set of types is finite. That is exactly what dkl has shown above and what one would call "explicit instantiation". So the template is only allowed to be used with the types for which an explicit instantiation exists in any module (but only once). There's no special compiler support needed for this to work.
2. Provide the template implementation everywhere, where it is used, so that the compiler can instantiate it always for any type it encounters. As the compiler cannot know about other modules this will usually lead to a lot of duplicated instantiations (when we assume that the compiler just instantiates the template for every new type it encounters for every module separately). Duplicate instantiations are a problem, though, so e.g. the linker has to remove the duplicates and thus has to explicitly support templates. I don't know how common C++ toolchains implement this (object files would be blown up if they did it like I assumed) - maybe some C++ expert could tell me? I'd really like to know it.
While the compilation of single modules could be done that way in FB with preprocessor-stuff, I don't see a possibility to eliminate the duplicates during linking or somehow else.
3. maybe other solutions??