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"));
wilx
  • 17,697
  • 6
  • 59
  • 114
Dani
  • 14,639
  • 11
  • 62
  • 110

1 Answers1

6

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

wilx
  • 17,697
  • 6
  • 59
  • 114
  • 1
    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. – wilx Sep 16 '13 at 18:35
  • Yes, I've used the unicode version, I might need it anyways... not for the log but for the rest of the project... – Dani Sep 16 '13 at 18:36
  • Why should we use the "Release_Unicode" instead of "Release"? If i want to use "Release" what should I do? – Saurabh B Feb 28 '14 at 07:19
  • 1
    @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::string`s instead of `std::wstring`. – wilx Feb 28 '14 at 11:20