I\'ve been working on compiling with Visual Studio 2015 a large number of code files written originally for use on linux, using g++. Specifically, I need a .dll for use with
The static data in the dll is in a different address space so you can't directly reference it (the call has to be mapped thru an import table). When you link a static library everything is in the address space of the executable so you can.
You must use dllexport and dllimport as a pair. dllexport where you define them in the shared library (dll) and dllimport where you use them in the application. You'll typically have a macro that evaluates to either __declspec(dllexport) or __declspec(dllimport) depending on where it's used. E.g.
#ifdef _DLL // inside the DLL
#define DLLExportImport __declspec(dllexport)
#else // outside the DLL
#define DLLExportImport __declspec(dllimport)
#endif
And use it where you define the class:
class DLLExportImport FirstClass
{ ... };
Defining the symbol _DLL
as appropriate in the respective projects. Visual Studio predefines _DLL
when you create a new dll project.
There is no need for .def files in most cases these days.