-1

MS Visual Studio 2008. This seems to be a name mangling issue, but I can't find the right search terms to come up with an answer.

I have a dynamic lib that has a class in it, which is using a logging class from a static logging library. The dynamic lib imports the static library in the project settings. I use this static lib in other projects, so I know it compiles and links without error.

Sample code:

Dynamic.h:

extern "C"
{
  __declspec(dllexport) BYTE GetData();
};

Dynamic.cpp:

#include "MyClass.h"

static MyClass g_Inst;

BYTE GetData() { return g_Inst.GetData(); }

MyClass.h:

#include "Logging.h"

class MyClass
{
public:
  BYTE GetData() { CLogging::Instance().AddString("Test"); }
};

Linker:

error LNK2019: unresolved external symbol "public: void __cdecl CLogging::AddString(class ATL::CStringT<wchar_t,class StrTraitMFC<wchar_t,class ATL::ChTraitsOS<wchar_t> > > const &)" (?AddString@CLogging@@QAAXABV?$CStringT@_WV?$StrTraitMFC@_WV?$ChTraitsOS@_W@ATL@@@@@ATL@@@Z) referenced in function "public: unsigned char __cdecl MyClass::GetData(void)" (?GetData@MyClass@@QAAEXZ)

Edit: thinking maybe it was a Unicode or MFC issue, I checked on the project settings for the Dynamic project:

Dynamic project settings

The Logging project:

Logging project settings

And two other projects that also pull in Logging with no problems:

Working project settings 1

Working project settings 2

The only difference I can see is the one that doesn't work is built as a dynamic dll.

JoeFish
  • 3,009
  • 1
  • 18
  • 23

1 Answers1

0

While maybe incidental, the error seems to indicate that the linker cannot find the wide-character version of ATL::CStringT<> (note instances of wchar_t following):

error LNK2019: unresolved external symbol "public: void __cdecl CLogging::AddString(class ATL::CStringT<wchar_t,class StrTraitMFC<wchar_t,class ATL::ChTraitsOS<wchar_t> > > const &)" (?AddString@CLogging@@QAAXABV?$CStringT@_WV?$StrTraitMFC@_WV?$ChTraitsOS@_W@ATL@@@@@ATL@@@Z) referenced in function "public: unsigned char __cdecl MyClass::GetData(void)" (?GetData@MyClass@@QAAEXZ)

You might check your project settings, and try to build using a non-Unicode character set.

Phil Brubaker
  • 1,257
  • 3
  • 11
  • 14
  • That was my first thought, but I double-checked, and all projects are using the same "Use Unicode Character Set" setting. I also pull this Logging project into other projects that also use Unicode with no issues. – JoeFish Apr 04 '17 at 20:02
  • Something else to check: In some versions of Visual Studio, there is an option to compile with `wchar_t` as a native type or not (some description here: https://msdn.microsoft.com/en-us/library/dh8che7s.aspx). I've definitely seen issues where projects won't cooperate if these settings don't match. – Phil Brubaker Apr 04 '17 at 20:16