5

I've download and compiled log4cplus in VS2012. Compilation was fine (both debug and release) I've tried to use it my code but I get 3 link errors, nothing I tried didn't remove them. I'm using the same includes from the log4cplus project, and the libs I've compiled (tried all 3... debug release and the log4cplusS.lib

I still get these:

error LNK2019: unresolved external symbol "__declspec(dllimport) class std::basic_ostringstream,class std::allocator > & __cdecl log4cplus::detail::get_macro_body_oss(void)" (_imp?get_macro_body_oss@detail@log4cplus@@YAAAV?$basic_ostringstream@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@XZ) referenced in function "int __cdecl Prepare(class std::basic_string,class std::allocator > &,class std::basic_string,class std::allocator > &,class std::basic_string,class std::allocator > &,int *,int *,int *)" (?Prepare@@YAHAAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@00PAH11@Z)

error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string,class std::allocator > const &)" (_imp?getInstance@Logger@log4cplus@@SA?AV12@ABV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@Z) referenced in function "int __cdecl Prepare(class std::basic_string,class std::allocator > &,class std::basic_string,class std::allocator > &,class std::basic_string,class std::allocator > &,int *,int *,int *)" (?Prepare@@YAHAAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@00PAH11@Z)

What is wrong?

My code is simple, in my dll cpp:

in the top of cpp I added

static Logger logger;

in one of the function I've added:

logger = Logger::getInstance(LOG4CPLUS_TEXT("MyDLL"));
LOG4CPLUS_INFO(logger, LOG4CPLUS_TEXT("Prepare Starts"));

1 Answer 1

6

It is likely that you have compiled log4cplus using the Release configuration. You will need to use Release_Unicode (similarly for Debug configuration).

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

4 Comments

Since Visual Studio 2010 (I believe), all new projects are created with TCHAR as wchar_t (Unicode setting in General settings group). This setting defines the UNICODE and _UNICODE preprocessor symbols. These symbols are used by log4cplus as well. If you absolutely want to disable this, you can, but I would suggest against that for anything that is not a toy project.
Yes, I've used the unicode version, I might need it anyways... not for the log but for the rest of the project...
Why should we use the "Release_Unicode" instead of "Release"? If i want to use "Release" what should I do?
@Hawk_85: You can of course do that. But then your own application using log4cplus must be compiled without UNICODE and _UNICODE defined. IOW, your own application will have to be interfacing with log4cplus with plain std::strings instead of std::wstring.

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.