log4cxx library

M

msosno01

log4cxx is an excellent library for logging with a huge amount
features:
http://logging.apache.org/log4cxx/manual/Introduction.html
My friend persuaded me to install it. However, I have a problem
compiling a simple program. This is the program:
#include <iostream>
#include "server.h"

#include <log4cxx/logger.h>
#include <log4cxx/ndc.h>
#include <log4cxx/basicconfigurator.h>
#include <log4cxx/propertyconfigurator.h>
#include <log4cxx/helpers/exception.h>

using namespace std;
using namespace ost;
using namespace log4cxx;
using namespace log4cxx::helpers;

int main()
{
int result = EXIT_SUCCESS;
try
{
BasicConfigurator::configure();
LoggerPtr rootLogger = Logger::getRootLogger();

NDC::push(_T("trivial context"));

rootLogger->debug(_T("debug message"));
rootLogger->info(_T("info message"));
rootLogger->warn(_T("warn message"));
rootLogger->error(_T("error message"));
rootLogger->fatal(_T("fatal message"));
}
catch(Exception&)
{
result = EXIT_FAILURE;
}

return result;

}
I receive these error messages:
In function `main':
: undefined reference to `log4cxx::BasicConfigurator::configure()'
/home/maksim/tmp/ccvVAxjg.o(.text+0x44): In function `main':
: undefined reference to `log4cxx::Logger::getRootLogger()'

I included all the header files needed. I think the problem is in how I
compile the program. Most likely, I miss a flag:
g++ -D_REENTRANT -pipe -O3 -march=i586 -fomit-frame-pointer
-I/home/maksim/projects/log4cxx-0.9.7/include -D_GNU_SOURCE
-L/usr/local/lib -lccgnu2 -ldl -lrt -pthread *.cpp -o server

Any help is appreciated (my program also uses GNU common C++ library).
 
V

Victor Bazarov

log4cxx is an excellent library for logging [..]

undefined reference to `log4cxx::BasicConfigurator::configure()'
/home/maksim/tmp/ccvVAxjg.o(.text+0x44): In function `main':
undefined reference to `log4cxx::Logger::getRootLogger()'

I included all the header files needed. I think the problem is in how
I compile the program. Most likely, I miss a flag:
g++ -D_REENTRANT -pipe -O3 -march=i586 -fomit-frame-pointer
-I/home/maksim/projects/log4cxx-0.9.7/include -D_GNU_SOURCE
-L/usr/local/lib -lccgnu2 -ldl -lrt -pthread *.cpp -o server

Sorry, compiler-specific command-line options are off-topic here.
Please post to the g++ newsgroup: gnu.g++.help.

V
 
B

Bruintje Beer

log4cxx is an excellent library for logging with a huge amount
features:
http://logging.apache.org/log4cxx/manual/Introduction.html
My friend persuaded me to install it. However, I have a problem
compiling a simple program. This is the program:
#include <iostream>
#include "server.h"

#include <log4cxx/logger.h>
#include <log4cxx/ndc.h>
#include <log4cxx/basicconfigurator.h>
#include <log4cxx/propertyconfigurator.h>
#include <log4cxx/helpers/exception.h>

using namespace std;
using namespace ost;
using namespace log4cxx;
using namespace log4cxx::helpers;

int main()
{
int result = EXIT_SUCCESS;
try
{
BasicConfigurator::configure();
LoggerPtr rootLogger = Logger::getRootLogger();

NDC::push(_T("trivial context"));

rootLogger->debug(_T("debug message"));
rootLogger->info(_T("info message"));
rootLogger->warn(_T("warn message"));
rootLogger->error(_T("error message"));
rootLogger->fatal(_T("fatal message"));
}
catch(Exception&)
{
result = EXIT_FAILURE;
}

return result;

}
I receive these error messages:
In function `main':
: undefined reference to `log4cxx::BasicConfigurator::configure()'
/home/maksim/tmp/ccvVAxjg.o(.text+0x44): In function `main':
: undefined reference to `log4cxx::Logger::getRootLogger()'

I included all the header files needed. I think the problem is in how I
compile the program. Most likely, I miss a flag:
g++ -D_REENTRANT -pipe -O3 -march=i586 -fomit-frame-pointer
-I/home/maksim/projects/log4cxx-0.9.7/include -D_GNU_SOURCE
-L/usr/local/lib -lccgnu2 -ldl -lrt -pthread *.cpp -o server

Any help is appreciated (my program also uses GNU common C++ library).

Hi,

I guess you forget a namespace

John
 
S

Stephane Wirtel

Can you add the include & library path of log4cxx to your project ?

It didn't find references, because you didn't specify the library path
 
R

Roland Pibinger

I receive these error messages:
In function `main':
: undefined reference to `log4cxx::BasicConfigurator::configure()'
/home/maksim/tmp/ccvVAxjg.o(.text+0x44): In function `main':
: undefined reference to `log4cxx::Logger::getRootLogger()'

This is a linker error ...
I included all the header files needed. I think the problem is in how I
compile the program. Most likely, I miss a flag:

.... not a compiler error. Most likely you need to compile the library
and link the result to your application (e.g. with -lmylibname)
g++ -D_REENTRANT -pipe -O3 -march=i586 -fomit-frame-pointer
-I/home/maksim/projects/log4cxx-0.9.7/include -D_GNU_SOURCE
-L/usr/local/lib -lccgnu2 -ldl -lrt -pthread *.cpp -o server

Any help is appreciated (my program also uses GNU common C++ library).

Try to find out how linking (of shared libraries) works on your
platform, also how include and library paths should be set up.

Best wishes,
Roland Pibinger
 
M

msosno01

I added the path to the library, but now I am getting a run-time error:
cannot open shared object file: No such file or directory

I think that I installed log4cxx correctly since I followed all the
steps. Does that error message mean that log4cxx is not installed
correctly?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top