0

I have seen many c++ header file under MSVC environment like this:

#ifdef somelib_EXPORTS
#define DLLEXPORTS __declspec(dllexport)
#else
#define DLLEXPORTS __declspec(dllimport)
#endif

Where does the <libname>_EXPORTS convention come from ?

Is it a Visual Studio's default macro ? Or is it generated by CMake ?

I can't find any document about this convention.

flm8620
  • 1,411
  • 11
  • 15
  • 1
    It is probably generated by the default project template included with Visual Studio. But it's just convention—it has no other meaning. You can use any name you want. See more generally: http://stackoverflow.com/questions/8863193/what-does-declspecdllimport-really-mean – Cody Gray - on strike Jan 30 '17 at 16:23
  • Nothing to do with CMake, this convention has been in use well before that even existed. – Dan Mašek Jan 30 '17 at 16:24
  • `CMake` documentation says that the default macro from `CMake` is `LIBNAME_EXPORT` https://cmake.org/cmake/help/v3.0/module/GenerateExportHeader.html however it's easy to change the default or the library may generate a similar header without using GenerateExportHeader. – drescherjm Jan 30 '17 at 16:38

1 Answers1

0

Where does the _EXPORTS convention come from ?

This is general coding guideline that helps with making sure that a .h file can be #included while building a DLL and by the users of the DLL.

The name DLLEXPORTS is project specific. It can be generated by CMake, qmake, or manually. I don't think Visual Studio can generate them, at least I haven't seen that.

If you have 10 DLLs in your project, you will end up using 10 such macros. For example, you might have UTILITY_DLL_EXPORT, MESSAGING_DLL_EXPORT, KERNEL_DLL_EXPORT, etc.

R Sahu
  • 204,454
  • 14
  • 159
  • 270