I have a rather big Core
project that I'm working with, I'm attempting to adapt it to use a DLL Engine I've built, I'm getting a bunch of errors like:
unresolved external symbol "private: static class
When including some of the headers from the Core in the DLL, the class is exported via __declspec(dllexport) but any header with static members throws out a crapload of errors regarding the static members.
This is a rather big project, I can't exactly run around removing every static class member I see, is there anyway around this kind of thing?
A basic example of a class that's being imported:
class __declspec(dllexport) MyClass
{
public:
static bool m_someVar;
}
For clarity sake I'd just like to address that m_someVar is defined/declared (forget the term) in the classes implementation file
When you compile the Core
you want these functions to be dllexport
; However, when you compile the DLL, you want them to be dllimport
. In your case, you're always defining them as dllexport
, thus when you link the DLL it complains that you've declared a function (and even said you'd export it) without ever defining it.
The solution is simple. Instead of manually __declspec
ing, create a macro based on whether you're the Core
or the DLL:
#ifndef I_AM_A_DLL
#define EXPORT __declspec(dllexport)
#define IMPORT __declspec(dllimport)
#else
#define EXPORT __declspec(dllimport)
#define IMPORT __declspec(dllexport)
#endif
Use EXPORT
for functions in the Core
and IMPORT
for functions in external DLLs:
class EXPORT MyClass
{
public:
static bool m_someVar;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With