ld error when building latest git version. undefined reference to log4cpp::Appender ...

Doron Behar doron.behar at gmail.com
Thu Dec 13 13:16:36 UTC 2018


Thanks for your reply, I was able to workaround this by adding the
following flags my `cmake` command:

-DCMAKE_EXE_LINKER_FLAGS=-llog4cpp
-DCMAKE_MODULE_LINKER_FLAGS=-llog4cpp
-DCMAKE_SHARED_LINKER_FLAGS=-llog4cpp

I'm not an expert in build systems but my guess is that the shared
libraries which all of these objects were built against depend on
log4cpp and linking them into a single file requires `-llog4cpp`.

I have no experience in writing cmake rules but I tried to patch
CMakeLists.txt without much success, I suppose more experience is needed
:) WIP patch is attached.

I hope you'll find time to look into this and help me help you.

Thanks again.

On Thu, Dec 13, 2018 at 09:56:26AM +0000, Müller, Marcus (CEL) wrote:
> Hi Doron,
> 
> my guess is that you updated the log4cpp header files, but your ld is
> still linking to an older version of log4cpp, or vice versa.
> Since (as far as I know), gr-osmosdr doesn't use log4cpp itself at all,
> this would, for example, happen, if you have a GNU Radio installed that
> was built agains an older version of log4cpp, and then you've updated
> log4cpp, and now are trying to build software that links agains GNU
> Radio.
> 
> Best regards,
> Marcus
> On Wed, 2018-12-12 at 22:44 +0200, Doron Behar wrote:
> > So I wanted to compile gr-osmosdr from source. I created a build
> > directory and I ran `cmake ..` and then `make`.
> > 
> > These are the errors I got:
> > 
> > ```
> > [ 57%] Linking CXX shared library libgnuradio-osmosdr-0.1.5git.so
> > /usr/bin/ld: CMakeFiles/gnuradio-osmosdr.dir/source_impl.cc.o: in
> > function `_GLOBAL__sub_I_source_impl.cc':
> > source_impl.cc:(.text.startup+0x54): undefined reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::AppenderMapStorage
> > Initializer()'
> > /usr/bin/ld: source_impl.cc:(.text.startup+0x6b): undefined reference
> > to
> > `log4cpp::Appender::AppenderMapStorageInitializer::~AppenderMapStorag
> > eInitializer()'
> > /usr/bin/ld: CMakeFiles/gnuradio-osmosdr.dir/sink_impl.cc.o: in
> > function `_GLOBAL__sub_I_sink_impl.cc':
> > sink_impl.cc:(.text.startup+0x54): undefined reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::AppenderMapStorage
> > Initializer()'
> > /usr/bin/ld: sink_impl.cc:(.text.startup+0x6b): undefined reference
> > to
> > `log4cpp::Appender::AppenderMapStorageInitializer::~AppenderMapStorag
> > eInitializer()'
> > /usr/bin/ld: CMakeFiles/gnuradio-osmosdr.dir/device.cc.o: in function
> > `_GLOBAL__sub_I_device.cc':
> > device.cc:(.text.startup+0x60): undefined reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::AppenderMapStorage
> > Initializer()'
> > /usr/bin/ld: device.cc:(.text.startup+0x67): undefined reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::~AppenderMapStorag
> > eInitializer()'
> > /usr/bin/ld: CMakeFiles/gnuradio-
> > osmosdr.dir/osmosdr/osmosdr_src_c.cc.o: in function
> > `_GLOBAL__sub_I_osmosdr_src_c.cc':
> > osmosdr_src_c.cc:(.text.startup+0x54): undefined reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::AppenderMapStorage
> > Initializer()'
> > /usr/bin/ld: osmosdr_src_c.cc:(.text.startup+0x6b): undefined
> > reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::~AppenderMapStorag
> > eInitializer()'
> > /usr/bin/ld: CMakeFiles/gnuradio-osmosdr.dir/file/file_source_c.cc.o: 
> > in function `_GLOBAL__sub_I_file_source_c.cc':
> > file_source_c.cc:(.text.startup+0x54): undefined reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::AppenderMapStorage
> > Initializer()'
> > /usr/bin/ld: file_source_c.cc:(.text.startup+0x6b): undefined
> > reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::~AppenderMapStorag
> > eInitializer()'
> > /usr/bin/ld: CMakeFiles/gnuradio-osmosdr.dir/file/file_sink_c.cc.o:
> > in function `_GLOBAL__sub_I_file_sink_c.cc':
> > file_sink_c.cc:(.text.startup+0x54): undefined reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::AppenderMapStorage
> > Initializer()'
> > /usr/bin/ld: file_sink_c.cc:(.text.startup+0x6b): undefined reference
> > to
> > `log4cpp::Appender::AppenderMapStorageInitializer::~AppenderMapStorag
> > eInitializer()'
> > /usr/bin/ld: CMakeFiles/gnuradio-osmosdr.dir/rtl/rtl_source_c.cc.o:
> > in function `_GLOBAL__sub_I_rtl_source_c.cc':
> > rtl_source_c.cc:(.text.startup+0x54): undefined reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::AppenderMapStorage
> > Initializer()'
> > /usr/bin/ld: rtl_source_c.cc:(.text.startup+0x6b): undefined
> > reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::~AppenderMapStorag
> > eInitializer()'
> > /usr/bin/ld: CMakeFiles/gnuradio-
> > osmosdr.dir/rtl_tcp/rtl_tcp_source_c.cc.o: in function
> > `_GLOBAL__sub_I_rtl_tcp_source_c.cc':
> > rtl_tcp_source_c.cc:(.text.startup+0x54): undefined reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::AppenderMapStorage
> > Initializer()'
> > /usr/bin/ld: rtl_tcp_source_c.cc:(.text.startup+0x6b): undefined
> > reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::~AppenderMapStorag
> > eInitializer()'
> > /usr/bin/ld: CMakeFiles/gnuradio-osmosdr.dir/uhd/uhd_sink_c.cc.o: in
> > function `_GLOBAL__sub_I_uhd_sink_c.cc':
> > uhd_sink_c.cc:(.text.startup+0x54): undefined reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::AppenderMapStorage
> > Initializer()'
> > /usr/bin/ld: uhd_sink_c.cc:(.text.startup+0x6b): undefined reference
> > to
> > `log4cpp::Appender::AppenderMapStorageInitializer::~AppenderMapStorag
> > eInitializer()'
> > /usr/bin/ld: CMakeFiles/gnuradio-osmosdr.dir/uhd/uhd_source_c.cc.o:
> > in function `_GLOBAL__sub_I_uhd_source_c.cc':
> > uhd_source_c.cc:(.text.startup+0x54): undefined reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::AppenderMapStorage
> > Initializer()'
> > /usr/bin/ld: uhd_source_c.cc:(.text.startup+0x6b): undefined
> > reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::~AppenderMapStorag
> > eInitializer()'
> > /usr/bin/ld: CMakeFiles/gnuradio-osmosdr.dir/miri/miri_source_c.cc.o: 
> > in function `_GLOBAL__sub_I_miri_source_c.cc':
> > miri_source_c.cc:(.text.startup+0x54): undefined reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::AppenderMapStorage
> > Initializer()'
> > /usr/bin/ld: miri_source_c.cc:(.text.startup+0x6b): undefined
> > reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::~AppenderMapStorag
> > eInitializer()'
> > /usr/bin/ld: CMakeFiles/gnuradio-
> > osmosdr.dir/hackrf/hackrf_source_c.cc.o: in function
> > `_GLOBAL__sub_I_hackrf_source_c.cc':
> > hackrf_source_c.cc:(.text.startup+0x58): undefined reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::AppenderMapStorage
> > Initializer()'
> > /usr/bin/ld: hackrf_source_c.cc:(.text.startup+0x5f): undefined
> > reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::~AppenderMapStorag
> > eInitializer()'
> > /usr/bin/ld: CMakeFiles/gnuradio-
> > osmosdr.dir/hackrf/hackrf_sink_c.cc.o: in function
> > `_GLOBAL__sub_I_hackrf_sink_c.cc':
> > hackrf_sink_c.cc:(.text.startup+0x58): undefined reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::AppenderMapStorage
> > Initializer()'
> > /usr/bin/ld: hackrf_sink_c.cc:(.text.startup+0x5f): undefined
> > reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::~AppenderMapStorag
> > eInitializer()'
> > /usr/bin/ld: CMakeFiles/gnuradio-
> > osmosdr.dir/bladerf/bladerf_source_c.cc.o: in function
> > `_GLOBAL__sub_I_bladerf_source_c.cc':
> > bladerf_source_c.cc:(.text.startup+0x54): undefined reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::AppenderMapStorage
> > Initializer()'
> > /usr/bin/ld: bladerf_source_c.cc:(.text.startup+0x6b): undefined
> > reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::~AppenderMapStorag
> > eInitializer()'
> > /usr/bin/ld: CMakeFiles/gnuradio-
> > osmosdr.dir/bladerf/bladerf_sink_c.cc.o: in function
> > `_GLOBAL__sub_I_bladerf_sink_c.cc':
> > bladerf_sink_c.cc:(.text.startup+0x54): undefined reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::AppenderMapStorage
> > Initializer()'
> > /usr/bin/ld: bladerf_sink_c.cc:(.text.startup+0x6b): undefined
> > reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::~AppenderMapStorag
> > eInitializer()'
> > /usr/bin/ld: CMakeFiles/gnuradio-
> > osmosdr.dir/rfspace/rfspace_source_c.cc.o: in function
> > `_GLOBAL__sub_I_rfspace_source_c.cc':
> > rfspace_source_c.cc:(.text.startup+0x54): undefined reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::AppenderMapStorage
> > Initializer()'
> > /usr/bin/ld: rfspace_source_c.cc:(.text.startup+0x6b): undefined
> > reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::~AppenderMapStorag
> > eInitializer()'
> > /usr/bin/ld: CMakeFiles/gnuradio-
> > osmosdr.dir/airspy/airspy_source_c.cc.o: in function
> > `_GLOBAL__sub_I_airspy_source_c.cc':
> > airspy_source_c.cc:(.text.startup+0x54): undefined reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::AppenderMapStorage
> > Initializer()'
> > /usr/bin/ld: airspy_source_c.cc:(.text.startup+0x6b): undefined
> > reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::~AppenderMapStorag
> > eInitializer()'
> > /usr/bin/ld: CMakeFiles/gnuradio-
> > osmosdr.dir/soapy/soapy_source_c.cc.o: in function
> > `_GLOBAL__sub_I_soapy_source_c.cc':
> > soapy_source_c.cc:(.text.startup+0x54): undefined reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::AppenderMapStorage
> > Initializer()'
> > /usr/bin/ld: soapy_source_c.cc:(.text.startup+0x6b): undefined
> > reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::~AppenderMapStorag
> > eInitializer()'
> > /usr/bin/ld: CMakeFiles/gnuradio-osmosdr.dir/soapy/soapy_sink_c.cc.o: 
> > in function `_GLOBAL__sub_I_soapy_sink_c.cc':
> > soapy_sink_c.cc:(.text.startup+0x54): undefined reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::AppenderMapStorage
> > Initializer()'
> > /usr/bin/ld: soapy_sink_c.cc:(.text.startup+0x6b): undefined
> > reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::~AppenderMapStorag
> > eInitializer()'
> > /usr/bin/ld: CMakeFiles/gnuradio-
> > osmosdr.dir/redpitaya/redpitaya_source_c.cc.o: in function
> > `_GLOBAL__sub_I_redpitaya_source_c.cc':
> > redpitaya_source_c.cc:(.text.startup+0x54): undefined reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::AppenderMapStorage
> > Initializer()'
> > /usr/bin/ld: redpitaya_source_c.cc:(.text.startup+0x6b): undefined
> > reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::~AppenderMapStorag
> > eInitializer()'
> > /usr/bin/ld: CMakeFiles/gnuradio-
> > osmosdr.dir/redpitaya/redpitaya_sink_c.cc.o: in function
> > `_GLOBAL__sub_I_redpitaya_sink_c.cc':
> > redpitaya_sink_c.cc:(.text.startup+0x54): undefined reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::AppenderMapStorage
> > Initializer()'
> > /usr/bin/ld: redpitaya_sink_c.cc:(.text.startup+0x6b): undefined
> > reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::~AppenderMapStorag
> > eInitializer()'
> > /usr/bin/ld: CMakeFiles/gnuradio-
> > osmosdr.dir/freesrp/freesrp_source_c.cc.o: in function
> > `_GLOBAL__sub_I_freesrp_source_c.cc':
> > freesrp_source_c.cc:(.text.startup+0x54): undefined reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::AppenderMapStorage
> > Initializer()'
> > /usr/bin/ld: freesrp_source_c.cc:(.text.startup+0x6b): undefined
> > reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::~AppenderMapStorag
> > eInitializer()'
> > /usr/bin/ld: CMakeFiles/gnuradio-
> > osmosdr.dir/freesrp/freesrp_sink_c.cc.o: in function
> > `_GLOBAL__sub_I_freesrp_sink_c.cc':
> > freesrp_sink_c.cc:(.text.startup+0x54): undefined reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::AppenderMapStorage
> > Initializer()'
> > /usr/bin/ld: freesrp_sink_c.cc:(.text.startup+0x6b): undefined
> > reference to
> > `log4cpp::Appender::AppenderMapStorageInitializer::~AppenderMapStorag
> > eInitializer()'
> > collect2: error: ld returned 1 exit status
> > make[2]: *** [lib/CMakeFiles/gnuradio-osmosdr.dir/build.make:555:
> > lib/libgnuradio-osmosdr-0.1.5git.so.0.0.0] Error 1
> > make[1]: *** [CMakeFiles/Makefile2:141: lib/CMakeFiles/gnuradio-
> > osmosdr.dir/all] Error 2
> > make: *** [Makefile:141: all] Error 2
> > ```
> > 
> > As you can see, all error messages refer to the same reference to a
> > log4cpp appender function.
> > 
> > I have log4cpp version 1.1.3 installed by my package manager on Arch
> > Linux. It is installed in /usr/lib. It seems like a missing library
> > in
> > CMakeLists.txt . Am I correct?
> > 
> > Thanks for creating this software.


-------------- next part --------------
>From fa470d0872404b94e9886071996959b7678a8105 Mon Sep 17 00:00:00 2001
From: Doron Behar <doron.behar at gmail.com>
Date: Thu, 13 Dec 2018 15:12:56 +0200
Subject: [PATCH] WIP - search for log4cpp so it's linker flag will be added

---
 CMakeLists.txt                  |  1 +
 cmake/Modules/FindLog4Cpp.cmake | 29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)
 create mode 100644 cmake/Modules/FindLog4Cpp.cmake

diff --git a/CMakeLists.txt b/CMakeLists.txt
index af21291..b1bf031 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -174,6 +174,7 @@ find_package(LibbladeRF)
 find_package(SoapySDR NO_MODULE)
 find_package(LibFreeSRP)
 find_package(Doxygen)
+find_package(Log4Cpp)
 
 if(NOT GNURADIO_RUNTIME_FOUND)
     message(FATAL_ERROR "GnuRadio Runtime required to build " ${CMAKE_PROJECT_NAME})
diff --git a/cmake/Modules/FindLog4Cpp.cmake b/cmake/Modules/FindLog4Cpp.cmake
new file mode 100644
index 0000000..530fa34
--- /dev/null
+++ b/cmake/Modules/FindLog4Cpp.cmake
@@ -0,0 +1,29 @@
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(PC_LOG4CPP log4cpp)
+
+FIND_PATH(
+    LOG4CPP_INCLUDE_DIRS
+    NAMES log4cpp/Appender.hh
+    HINTS $ENV{LOG4CPP_INCLUDE_DIRS}/include
+        ${PC_LOG4CPP_INCLUDEDIR}
+        ${CMAKE_INSTALL_PREFIX}/include
+    PATHS /usr/local/include
+          /usr/include
+)
+
+FIND_LIBRARY(
+    LOG4CPP_LIBRARIES
+    NAMES log4cpp
+    HINTS $ENV{LOG4CPP_DIR}/lib
+        ${PC_LOG4CPP_LIBDIR}
+        ${CMAKE_INSTALL_PREFIX}/lib64
+        ${CMAKE_INSTALL_PREFIX}/lib
+    PATHS /usr/local/lib
+          /usr/local/lib64
+          /usr/lib
+          /usr/lib64
+)
+
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(LOG4CPP DEFAULT_MSG LOG4CPP_LIBRARIES LOG4CPP_INCLUDE_DIRS)
+MARK_AS_ADVANCED(LOG4CPP_LIBRARIES LOG4CPP_INCLUDE_DIRS)
-- 
2.20.0



More information about the osmocom-sdr mailing list