-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.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
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: msdn.microsoft.com/en-us/library/dh8che7s.aspx). I've definitely seen issues where projects won't cooperate if these settings don't match.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.