0

I have a weird problem trying to link a simple code which use a personal library which uses lib4cplus.

The file with the main code is so easy and doesn't use log4cplus. I only use lib4cplus into the library. The library compiles correctly but when i link the main file with the library it thowrs errors like that (loggers var not defined under architecture x86_64)

g++ leer.cpp -c
ar r libfichero.a blowfish.o clase.o
g++ -o Class  leer.o -lm -lz -llog4cplus libfichero.a
Undefined symbols for architecture x86_64:
  "fichero::loggerFichero", referenced from:
      fichero::startLoggers()      in libfichero.a(clase.o)
      fichero::fichero()in libfichero.a(clase.o)
      fichero::fichero()in libfichero.a(clase.o)
  "fichero::errorLoggerFichero", referenced from:
      fichero::startLoggers()      in libfichero.a(clase.o)
      fichero::fichero()in libfichero.a(clase.o)
      fichero::fichero()in libfichero.a(clase.o)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make[1]: *** [all] Error 1
make: *** [p21] Error 2

The errors comes when i want to define my private logger vars (ficheroLogger and errorFicheroLogger).

That's the code in the cpp file of my library.

bool fichero::startLoggers()
{
    // Aquí inico los loggers que voy a usar en la clase.
    loggerFichero = Logger::getInstance(LOG4CPLUS_TEXT("utils"));
    errorLoggerFichero = Logger::getInstance("BigFail");
}


// Método para definir los logs.
bool fichero::initLogFichero()
{
    cout << "Entering LOG Config part..." << endl;
    LogLog::getLogLog()->setInternalDebugging(true);
    Logger root = Logger::getRoot();

    // Load the properties
    PropertyConfigurator::doConfigure("ficheroLog4cplus.properties");

    Logger fileLog = Logger::getInstance(LOG4CPLUS_TEXT("filelogger"));

    // Log with INFO level
    LOG4CPLUS_INFO(fileLog, "Application startup");

    cout << "Exiting the main part()..." << endl;

    // Log with INFO level
    if (fileLog.isEnabledFor(INFO_LOG_LEVEL))
    {
        LOG4CPLUS_WARN(fileLog, "Application shutdown");
    }

    startLoggers();

    return true;
}

// Constructor y Destructor
fichero::fichero()
{
    nomFile = "file.txt";

    delimitador = "";
    hayDelimiatador = false;

    initLogFichero();

    LOG4CPLUS_WARN(loggerFichero, "Inicio normal");
    LOG4CPLUS_WARN(errorLoggerFichero, "Inicio error.");
}
wilx
  • 17,697
  • 6
  • 59
  • 114
Jorge Vega Sánchez
  • 7,430
  • 14
  • 55
  • 77

1 Answers1

0

This does not look a like a problem of log4cplus. Try to reshuffle the command line:

g++ -o Class leer.o libfichero.a -llog4cplus -lz -lm
wilx
  • 17,697
  • 6
  • 59
  • 114