2

It's the second day I'm trying to marry Qt5, MinGW and log4cxx.

Even after I've compiled everything successfully, linked apr, apr-util and log4cxx libraries, ld gives me a bunch of "undefined reference" problems.

It looks like different settings were specified during log4cxx compilation (I'm using ant). Was anyone able to successfully compile and use log4cxx with MinGW?

Environment:

  • log4cxx trunk
  • apr 1.4.6
  • apr-util 1.5.2
  • latest MinGW
  • I'm using Qt 5 with latest MinGW as a compiler

What I've done:

  • compiled log4cxx using ant with the following command: "ant -Dcompiler=gcc -Dfind=false -DLOG4CXX_STATIC=1 -Dlib.type=static"
  • added result libraries to my project in pro file: "LIBS += -L../log4cxx/lib LIBS += -llibapr-1 -llibaprutil-1 -lliblog4cxx"

And now, as I try to link my project, I'm getting the next:

*C:/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'C:/Work/SPP_Development/AutoHaul/Sub-systems/TCS/Source/build-SimulatorEngine-Standalone_MinGW-Debug'
g++ -Wl,-subsystem,windows -mthreads -o debug\SimulatorEngine.exe object_script.SimulatorEngine.Debug  -lmingw32 -lqtmaind -L../log4cxx/lib -llibapr-1 -llibaprutil-1 -lliblog4cxx -LC:\Qt\Qt5.0.1\5.0.1\mingw47_32\lib -lQt5XmlPatternsd -lQt5Widgetsd -lQt5Networkd -lQt5Xmld -lQt5Guid -lQt5Cored -llibEGLd -llibGLESv2d -lgdi32 -luser32 
Makefile.Debug:200: recipe for target 'debug\SimulatorEngine.exe' failed
mingw32-make[1]: Leaving directory 'C:/Work/SPP_Development/AutoHaul/Sub-systems/TCS/Source/build-SimulatorEngine-Standalone_MinGW-Debug'
Makefile:34: recipe for target 'debug' failed
../log4cxx/lib/liblog4cxx.lib(mutex.o): In function `ZN7log4cxx7helpers5MutexC2ERNS0_4PoolE':
c:/Work/log4cxx/apache-log4cxx-trunc/src/main/cpp/mutex.cpp:35: undefined reference to `apr_thread_mutex_create@12'
../log4cxx/lib/liblog4cxx.lib(mutex.o): In function `ZN7log4cxx7helpers5MutexC2EP10apr_pool_t':
c:/Work/log4cxx/apache-log4cxx-trunc/src/main/cpp/mutex.cpp:45: undefined reference to `apr_thread_mutex_create@12'
../log4cxx/lib/liblog4cxx.lib(mutex.o): In function `ZN7log4cxx7helpers5MutexD2Ev':
c:/Work/log4cxx/apache-log4cxx-trunc/src/main/cpp/mutex.cpp:55: undefined reference to `apr_thread_mutex_destroy@4'*

It looks like log4cxx library cannot findfunctions declared and defined in the apr library by whatever reason.

Is there any way to analyze the problem further to see why is this happening?

rubenvb
  • 74,642
  • 33
  • 187
  • 332
Vlad
  • 301
  • 4
  • 10
  • Qt has nothing to do with log4cxx and vice versa. Undefined reference results in the fact that you don't link properly with either Qt or log4cxx. From your current post it is unclear undefined references to which symbols you get. Expand your question with the linker output to get more help. – Alexander Shukaev Apr 09 '13 at 15:46
  • You're right, should've provided more details. Original question updated. – Vlad Apr 09 '13 at 23:10

2 Answers2

1

I will describe the 1st problem you have and give the solution for it. If it does not solve your problem, do not revert back because that would be just the 1st step of fixing process, and I will gradually expand the answer to solve more incoming issues as long as you provide relevant feedback on each fix until we finally nail it down. So, lets begin.

First of all, you add libraries into LIBS variable in a wrong way. You have 2 options to do it right:

#1

LIBS += $${PWD}/../log4cxx/lib/libapr-1.a
LIBS += $${PWD}/../log4cxx/lib/libaprutil-1.a
LIBS += $${PWD}/../log4cxx/lib/liblog4cxx-1.a

#2

LIBS += -L$${PWD}/../log4cxx/lib
LIBS += -lapr-1
LIBS += -laprutil-1
LIBS += -llog4cxx-1

NOTE: Of course one liner is possible too:

LIBS += -L$${PWD}/../log4cxx/lib -lapr-1 -laprutil-1 -llog4cxx-1

NOTE: Using line continuation (\) for readability is possible too:

LIBS += -L$${PWD}/../log4cxx/lib \
        -lapr-1                  \
        -laprutil-1              \
        -llog4cxx-1
Alexander Shukaev
  • 16,674
  • 8
  • 70
  • 85
1

You need to take care of the proper link order: liblog4cxx depends on libapr*, so the libapr entries need to come after liblog4cxx:

LIBS += -L../log4cxx/lib \
        -llog4cxx-1 \
        -lapr-1 \
        -laprutil-1

The reason is that dependencies are resolved left to right, so that in your case the apr libraries have been read, and forgotten, when log4cxx comes along that has some external symbols that need resolving. ld won't read the apr libraries again (has to do with cyclic dependency issues, and historical reasons).

To test if this works, you can try running the command

g++ -Wl,-subsystem,windows -mthreads -o debug\SimulatorEngine.exe object_script.SimulatorEngine.Debug  -lmingw32 -lqtmaind -L../log4cxx/lib -lliblog4cxx -llibapr-1 -llibaprutil-1 -LC:\Qt\Qt5.0.1\5.0.1\mingw47_32\lib -lQt5XmlPatternsd -lQt5Widgetsd -lQt5Networkd -lQt5Xmld -lQt5Guid -lQt5Cored -llibEGLd -llibGLESv2d -lgdi32 -luser32

from the directory

C:/Work/SPP_Development/AutoHaul/Sub-systems/TCS/Source/build-SimulatorEngine-Standalone_MinGW-Debug

yourself first. But perhaps just modifying the .pro file is simplest.

rubenvb
  • 74,642
  • 33
  • 187
  • 332