Does the template really export to MSVC?

When you create a structure in your public interface in MSVC that contains a templated data element, you will receive a warning at compile time.

One solution is to export the template type to your DLL (see this article in KB format).

I ask this question because I do not understand why you want to export this type?

  • If you do not export it, the .hpp files have enough information to generate the type yourself.

  • If this is a standard type of library and you have 2 or more dlls, each of which is potentially associated with a different version of the standard library, now you have several binary versions of the same types in your code.

What's the point? Case # 1 can lead to runtime crashes if there really are two different versions that, according to the compiler, are the same, but # 2 might just not load due to missing characters?

Am I completely out of here? In my opinion, the best option is to simply ignore warnings from MSVC.

EDIT: so far no one has pointed this out, but I know and understand that if you have statics in your templates and you want these statics to be available for all kinds of uses of your DLL inside one application: you should, in this case export the template instance. This is important in the case of single-user objects and registrars, etc.

+4
source share
1 answer

#2 - instant death. If you want to use standard types in a DLL interface, you must ensure that the code you use a) is dynamically linked to the same CRT DLLs and b) compiled with the same headers.

#1 exists because you cannot guarantee that the called code has the same as you, for example, specializations, etc. There is nothing wrong if you yourself wrote a class and guarantee that the client and the DLL will see exactly the same class.

+1
source

Source: https://habr.com/ru/post/1342593/


All Articles