logging-log4cxx icon indicating copy to clipboard operation
logging-log4cxx copied to clipboard

Error building log4cxx with cmake, APR_STATIC and APU_STATIC options

Open clobotorre opened this issue 1 year ago • 2 comments

Based on the answer to this issue https://github.com/apache/logging-log4cxx/issues/362 I have done following steps on both Ubuntu 18.04 and Ubuntu 22.04.

Initial steps

	# mkdir /home/test_build_log4cxx_with_static_apr_libs
	# mkdir /home/test_build_log4cxx_with_static_apr_libs/target

libapr compilation steps

	# cd /home/test_build_log4cxx_with_static_apr_libs
	# mkdir apr
	# cd apr
	# curl -L -O https://archive.apache.org/dist/apr/apr-1.7.4.tar.bz2
	# tar xf apr-1.7.4.tar.bz2
	# cd apr-1.7.4
	# touch libtoolT
	# export CFLAGS=-fPIC
	# ./configure --prefix=/home/test_build_log4cxx_with_static_apr_libs/target
	# make install

libapr-util compilation steps

	# cd /home/test_build_log4cxx_with_static_apr_libs/apr
	# curl -L -O https://archive.apache.org/dist/apr/apr-util-1.6.3.tar.bz2
	# tar xf apr-util-1.6.3.tar.bz2
	# cd apr-util-1.6.3
	# export CFLAGS=-fPIC
	# ./configure --prefix=/home/test_build_log4cxx_with_static_apr_libs/target --with-apr=/home/test_build_log4cxx_with_static_apr_libs/target
	# make install	

log4cxx compilation steps

	# cd /home/test_build_log4cxx_with_static_apr_libs
	# mkdir log4cxx
	# cd log4cxx
	# curl -L -O https://dlcdn.apache.org/logging/log4cxx/1.2.0/apache-log4cxx-1.2.0.tar.gz
	# tar xzvf apache-log4cxx-1.2.0.tar.gz
	# cd apache-log4cxx-1.2.0
	# mkdir build
	# cd build
	# cmake -DAPR_STATIC=yes -DAPU_STATIC=yes -DCMAKE_PREFIX_PATH=/home/test_build_log4cxx_with_static_apr_libs/target/ ..
	# make
	# make install					

I have no problems on Ububntu 22.04, but on Ubuntu 18.04, the make command output ends like this:

[ 54%] Building CXX object src/test/cpp/CMakeFiles/autoconfiguretestcase.dir/autoconfiguretestcase.cpp.o
[ 54%] Linking CXX executable autoconfiguretestcase
../../main/cpp/liblog4cxx.so.15.2.0: undefined reference to `dlclose'
../../main/cpp/liblog4cxx.so.15.2.0: undefined reference to `dlsym'
../../main/cpp/liblog4cxx.so.15.2.0: undefined reference to `dlopen'
../../main/cpp/liblog4cxx.so.15.2.0: undefined reference to `dlerror'
collect2: error: ld returned 1 exit status
src/test/cpp/CMakeFiles/autoconfiguretestcase.dir/build.make:100: recipe for target 'src/test/cpp/autoconfiguretestcase' failed
make[2]: *** [src/test/cpp/autoconfiguretestcase] Error 1
CMakeFiles/Makefile2:1419: recipe for target 'src/test/cpp/CMakeFiles/autoconfiguretestcase.dir/all' failed
make[1]: *** [src/test/cpp/CMakeFiles/autoconfiguretestcase.dir/all] Error 2
Makefile:145: recipe for target 'all' failed
make: *** [all] Error 2

clobotorre avatar Apr 08 '24 16:04 clobotorre

If it's only the tests, you can just disable the tests(add -DBUILD_TESTING=OFF when configuring with cmake). Or, add -ldl to your linker flags.

Is there a particular reason it needs to be statically linked? Dynamically linking is the normal way to use log4cxx.

rm5248 avatar Apr 08 '24 17:04 rm5248

Thank you. I'll use -DBUILD_TESTING=OFF

I need APR libs statically linked because in the target machines there are already another (needed) version of APR libs wich conflicts with the ones needed by log4cxx.

clobotorre avatar Apr 08 '24 17:04 clobotorre