Why does my Visual C++ .exe project build create .lib and .exp files?

橙三吉。 提交于 2019-11-27 22:04:38

It's a bit late but, maybe someone else could find useful this hint.

BTW I'm not a c++ guru...

In my solution i have 3 projects. One is a dll project, the others are two Win32 app projects referencing the dll project.

Usually, with your dll built, you have also some others file generated (.exp, .lib) also for the NON dll projects. This can occour when you include a .h file of the dll project, into the app project, which contains a class marked with __declspec(dllexport).

To avoid the linker think your are trying to include some .h files to "export" use a conditional expression to define your _declspec macro.

Example:

#if defined(_DO_NOT_EXPORT)
#define DllExport  
#else
#define DllExport __declspec(dllexport)
#endif

Ok, let's say you have a MyClass.h in your dll project.

in your .h file you could have now:

class DllExport MyClass {
 ...
}

When you want to include this .h file into a NON dll project, you have simply to define the _DO_NOT_EXPORT condition

#define _DO_NOT_EXPORT
#include "MyClass.h"

This is normal if one or more functions is/are exported from your executable.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!