Click here to Skip to main content
15,918,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I ensure that i compiled log4cplus project as Dynamic Lib with Unicode charset(Debug_Unicode) and my own test project also had been set to Unicode charset. Both of them compiled under debug model. I have read many similar questions but still cannot resolve this problem... Following is my test code :
C++
#include "Include/log4cplus/loggingmacros.h"
#include "Include/log4cplus/configurator.h"
#include "Include/log4cplus/helpers/loglog.h"
#include "Include/log4cplus/helpers/stringhelper.h"
#include "Include/log4cplus/helpers/fileinfo.h"
#include "Include/log4cplus/loggingmacros.h"
#include "Include/log4cplus/initializer.h"
#pragma comment(lib, "log4cplusUD.lib")
using namespace std;
using namespace log4cplus;
using namespace log4cplus::helpers;
int main(int argc, wchar_t* argv[])
{

    cout << LOG4CPLUS_TEXT("Entering main()...") << endl;
    log4cplus::Initializer initializer;
    LogLog::getLogLog()->setInternalDebugging(true);
    Logger root = Logger::getRoot();
    try {
        PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT("E:\\log4cplus.properties"));
        Logger fileCat = Logger::getInstance(LOG4CPLUS_TEXT("filelogger"));

        LOG4CPLUS_WARN(root, LOG4CPLUS_TEXT("Testing...."));
        LOG4CPLUS_WARN(root, LOG4CPLUS_TEXT("Writing messages to log...."));
        for (int i = 0; i<10000; ++i)
            LOG4CPLUS_WARN(fileCat, LOG4CPLUS_TEXT("This is a WARNING...")
            << i);

        // Test that DOS EOLs in property files get removed.
#define TEST_TEXT LOG4CPLUS_TEXT ("this is a test with DOS EOL-->")
        tistringstream propsStream(
            LOG4CPLUS_TEXT("text=") TEST_TEXT LOG4CPLUS_TEXT("\r\n"));
        Properties props(propsStream);
        LOG4CPLUS_ASSERT(root,
            props.getProperty(LOG4CPLUS_TEXT("text")) == TEST_TEXT);
    }
    catch (...) {
        tcout << LOG4CPLUS_TEXT("Exception...") << endl;
        LOG4CPLUS_FATAL(root, LOG4CPLUS_TEXT("Exception occured..."));
    }
http://www.codeproject.com/Questions/ask.aspx#
    cout << LOG4CPLUS_TEXT("Exiting main()...") << endl;
    return 0;
}

I'm just copy this code from "propertyconfig_test" in log4cplus, the lib and dll file is also compiled with "Debug_Unicode",when I compiled my own test project then a link error occurs:
C++
  error LNK2001: unresolved external symbol "class std::basic_ostream<wchar_t,struct std::char_traits<wchar_t=""> > & log4cplus::tcout"
(?tcout@log4cplus@@3AAV?$basic_ostream@_WU?$char_traits@_W@std@@@std@@A)
       E:\TestCode\1026(thttpd)\thttpd\thttpd\thttpd.obj   thttpd

Just now,I found that if I comment these sentences which include the "tcout" function,then everything is OK,This example about propertyconfig_test works well,why?

What I have tried:

Try each compiled model and charset,read lots of similar questions
Posted
Updated 22-Nov-16 21:55pm
v3

At least older versions of Visual Studio have no definitions for tcout.

You might try to add them before including the log4cplus header files:
C++
#ifdef _UNICODE 
#define tcout std::wcout 
#define tcerr std::wcerr 
#else 
#define tcout std::cout 
#define tcerr std::cerr 
#endif 
 
Share this answer
 
The obvious problem is that the tcout implementation doesnt exist. Why arent you use cout?

Check where the tcout is declared and why it isnt compiled or implemented. I guess that some guarding macros are around.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900