[ENet-discuss] Building as a DLL

Brian Hook enet-discuss@cubik.org
Sat, 8 Mar 2003 11:19:49 -0800


ENet currently can't be built as a Windows DLL very easily because of 
symbol export (or lack thereof).  This can be solved one of two ways:

- rely on declspec( __dllexport ) and declspec( __dllimport ) and 
create a new define ENET_API.  Then you do something like this in 
"enet.h".

#ifdef ENET_API
#undef ENET_API
#endif

#if defined _MSC_VER && defined ENET_DLL
#if defined ENET_BUILDING_LIB
#define ENET_API __declspec( __dllexport )
#else
#define ENET_API __declspec( __dllimport )
#endif

#ifndef ENET_API
#define ENET_API
#endif

Then, inside all the library's source files, #define 
ENET_BUILDING_LIB before including "enet.h".  

If the user decides to build a DLL, they can simply define ENET_DLL 
and it all just magically works.

- create a .def file for Windows users which contains a list of all 
functions that would need to be exported from the DLL.

The first way is the easiest I think for everyone involved, but 
requires prefixing all exported API entry points with ENET_API.  I 
think this is a good idea, since it makes it abundantly clear which 
routines are public API points.

Brian