housefrommars housefrommars - 1 year ago 218
C++ Question

Undefined reference to log4cxx lib

I get error from the title when i try to build my project. I know that compiler is complaining that it can not find log4cxx but i am not sure why it can't.

log4cxx lib is in

and in my header file I have these lines

#include "log4cxx/logger.h"
#include "log4cxx/basicconfigurator.h"
#include "log4cxx/helpers/exception.h"

I know it can see them because if i change the path it throws an error that it can not find them. What am I doing wrong?

I haven't done anything in c++ for ages and i dropped out of the wagon so maybe this has a simple solution (I'm sure it does)

Answer Source

This is a linker error.

Try to compile while providing the name of the lib to the linker:

g++ ... -llog4cxx

To explain that, the compiler knows where the header files are when they are in a location like /usr/include. It knows where the libs are in these locations as well (here, we just wrote "-llog4cxx" without path and it can find /path/to/ But you must specify the name of the library you want to link with, and there is the compiler -l option to do that.

Read this for details!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download