How to use templates in a separate library?
frame
frame86 at live.com
Thu Jun 23 17:13:46 UTC 2022
On Thursday, 23 June 2022 at 08:12:32 UTC, CrazyMan wrote:
> I have a separate library and some template interface in it
>
> ```d
> interface IFoo(T)
> {
> void setValue(const(T) value);
> }
> ```
>
> But when using it in the main program, it throws a linking
> error. I found that you can make a sourceLibrary that copies
> the code instead of creating a binary. But with it, I also get
> a linking error, and at the same time it is no longer
> associated with my interface, but with a third-party dependency
> (bindbc.opengl)
>
> What can I do to fix this?
This is insufficient information to help you.
- Separate library could mean multiple things: a compiler
library, a static linked binary, a SO/DLL binary.
- What error is thrown?
- Are you using `extern` declarations?
For a successful build the linker needs to get all symbols from
any referenced source. The template isn't an actual symbol, it's
just a information for the compiler to generate one. It says
nothing about the symbol will be really generated or not. Also
the linker needs to know if a library has to be used.
More information about the Digitalmars-d-learn
mailing list