housefrommars housefrommars - 4 months ago 29
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

/usr/include/
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

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/liblog4cxx.so). 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!