mystor / rust-cpp

Embed C++ directly inside your rust code!
Apache License 2.0
795 stars 44 forks source link

duplicate typeinfo for templates #87

Closed luke-titley closed 3 years ago

luke-titley commented 3 years ago

So this is an issue I am facing. I'm wrapping quite a complex library that contains an std::vector like template class. The template is instantiated internally in the library but also externally in my wrapper (using cpp crate). The situation I am in, is that the type_info objects are independent, a dynamic cast on the template instantiation from my internal type will fail inside the library being wrapped.

I'm not 100% how to solve this, but I'm thinking along the lines of. Declare the template instantiation as external and then rely on the third party library to provide it. Unfortunately when I try this it seems the cpp crate fails to build as I get symbol missing errors when the static library of my c++ code is built.

I don't suppose you have any suggestions on how I could resolve this? I'm pretty stumped now for how to work around this issue. So any ideas you have would be really appreciated.

Thanks again!

ogoffart commented 3 years ago

I am not sure i understand the problem. Maybe some code example would help.

luke-titley commented 3 years ago

I think I got my wires crossed on this. The issue was a strange one, but I seem to have resolved it. I had marked the crate that was using cpp crate as dylib and ending up with duplicate type_info objects, which broken dynamic casting. No idea how it fixed it, but switching to rust lib fixed it.