Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export pure virtual functions from a DLL in C++?

I am having a strange problem that no pure virtual function is exporting from a DLL. DLL compiles and outputs as .dll file to the directory . But it doesn't produce .lib file.

If I give definition and it no longer remians as pure virtual, after that happily it creates .lib file.

I need to implement factory pattern for which I need to seperate interfaces and implementations. My factory implementation and other interfaces that use wanted .dll(of whome .lib file is not producing) need to use that exported function and when I use those functions they produce linking errors...

such as "error LNK2011: unresolved external symbol "public:......."

Have any one idea how to export pure virtual functions so that they can be implemented for other exe's and dll's

Regards Usman

like image 237
Hassan Avatar asked Dec 03 '22 11:12

Hassan


2 Answers

following link will clarify you doubts

Using dllimport and dllexport in C++ Classes

Not necessary to export class with only virtual/inline functions

like image 112
Ravi shankar Avatar answered Dec 29 '22 14:12

Ravi shankar


When you export something from a DLL you are creating an externally-visible name for something concrete in that DLL - a defined function or class. Without this, the link step for importing projects (those that reference that DLL) cannot resolve all required references to functions and classes in the exporting DLL.

For pure virtual functions, there is no concrete 'thing' in the exporting DLL: no linkable name can exist to resolve an external call to a pure virtual function - if there were, it would by definition not be pure. In this case, all that's needed is a declaration in a compile-time accessible header file of the pure virtual function, so that importing EXEs or DLLs know how to override it with a concrete function.

like image 37
Steve Townsend Avatar answered Dec 29 '22 15:12

Steve Townsend