Iyengar111 / NanoLog

Low Latency C++11 Logging Library
727 stars 186 forks source link

Support for dll builds in Win #20

Open cstamatopoulos opened 7 years ago

cstamatopoulos commented 7 years ago

Is this something that would interest you ? If yes I can make a pull request or I can paste the code here as it is only minor changes in the header file.

Iyengar111 commented 7 years ago

I'm not really sure what you mean by support for dll build. Why don't you raise the pull request, I'll have a look and hopefully get more clarity as well. In any case, I wouldn't want to add any thing that is windows specific to NanoLog. No platform specific code and using only standard headers was a strong design consideration.

cstamatopoulos commented 7 years ago

Currently, no symbols will be exported in MSVC. To do so you have to specify which symbols to export. This is usually done with the code shown below and it will be fine in all platforms. Note that most cross-platform c++ libraries do something similar, e.g. check fmt but it is up to you.

#if defined(_WIN32)
# ifdef NANO_LOG_EXPORT
#  define NANO_LOG_API __declspec(dllexport)
# elif defined(NANO_LOG_SHARED)
#  define NANO_LOG_API __declspec(dllimport)
# endif
#endif
#ifndef NANO_LOG_API
# define NANO_LOG_API
#endif

Then you need to add the NANO_LOG_API in classes and functions that have to be exported. In your case there are only 7 places where you need to do that. An example would be NANO_LOG_API void set_log_level(LogLevel level); If you are OK with that I can send a pull request otherwise feel free to close the issue.

crapp commented 7 years ago

@cstamatopoulos In case you are using cmake did you have a look at WINDOWS_EXPORT_ALL_SYMBOLS