I have a Logging class, which can be simplified to something like:
template <int TARGET>
struct Logging
{
static ostream * sOstream;
static void log(const char * _txt);
static void set_log_file(const char * _file_name)
{
sOstream = new ofstream(_file_name);
}
}
The whole thing works well in a single binary. However, I'd /like/ to be able to use Logging<TARGET_DEBUG>::log("some message");
inside a DLL, after having called Logging<TARGET_DEBUG>::set_log_file(someFilePath.c_str());
in an executable that uses that DLL. Originally, it didn't work because I wasn't exporting the class with __declspec(dllexport)
. However, when I add the appropriate macro to the logging class definition (header only), I get a series of error messages:
warning C4273: 'sOstream' : inconsistent dll linkage // why does this occur for a pointer?
error C2491: 'Logging::sOstream' : definition of dllimport static data member not allowed
Various other classes in the application are exported/imported without issue, but this is the only templated class I'm trying to share between binaries. It's not an area I'm overly familiar with so: how can I make this work as desired? Note the EXE includes the Logging struct with __declspec(dllimport)
, the DLLs with __declspec(dllexport)