You need to say which OS and compiler you are using...
But this looks a lot like Windows and MS compiler?
If so, my advice would be
- Forget the .DEF file, create a header file "MyDLL_config.h" instead. See below for what it should look like
- In your DLL project, define a symbol MYDLL_EXPORTS
- Include the "MyDLL_config.h" in the header files declaring exported functions/classes
- All functions and classes "tagged" with MYDLL_IMPORT_EXPORT as shown below will be exported
- For linux, the MYDLL_IMPORT_EXPORT symbol would be defined as blank (I think, but I have not tried.). I am guessing all functions and classes are exported from a linux .so
#ifndef MYDLL_CONFIG_H
#define MYDLL_CONFIG_H
#ifdef MYDLL_EXPORTS
#define MYDLL_IMPORT_EXPORT __declspec(dllexport)
#else
#define MYDLL_IMPORT_EXPORT __declspec(dllimport)
#endif
#endif
Example use in header file, exporting C++ functions and classes
#ifndef MYDLL_H
#define MYDLL_H
#include "MyDLL_config.h"
// example function prototype of exported function
MYDLL_IMPORT_EXPORT int example_function(int i);
// example class declaration of exported class
class MYDLL_IMPORT_EXPORT example_class {
public:
example_class();
virtual ~example_eclass();
void do_something();
private:
int m_whatever;
};
#endif
This technique ensures that the code is compiled with __declspec(dllexport) from within the MyDLL project, but any client code using the DLL would compile the header file using __declspec(dllimport). Obviously, the client projects must link with the export library (MyDll.lib).
Hope this helps.