Share Code between extensions (DEF-3348)(SOLVED)

I have a .h file which include a lot of struct and class definitions, and a lot of method declarations.
This .h file will be use by several native extensions, How can I include this .h file from these extensions?
I don’t want to use the extern keyword,because of these struct and class definitions.

Ideally, you shouldn’t generate code inside a .h file. That means: No method/constructor/destructor definitions for classes (unless they’re inline), no function definitions (unless they’re inline), no global variables unless declared with extern and defined in some other .cpp file, etc.

You’re free to declare anything (types, structs, classes, function signatures, extern global vars, macros, etc), but only define stuff inside a .cpp file. And the solution to your problem is to copy the same .h file across all extensions, but only include its corresponding .cpp file (the one with all the definitions) into one of the extensions. Shouldn’t matter which, as long as it’s linked together in the final executable.

2 Likes

@Mathias_Westerdahl is designing and thinking about a system where extensions can share code. It will likely be released in Q1.

1 Like

OK. I’m expecting it, and It will be better that java code can be shared between extensions.That is, java class will be defined in one extension,and imported by another extension.