#210 libcppunit.so: undefined reference to `dlsym' (with solution

1.12.1
open
nobody
5
2014-08-22
2012-12-03
No

Ubuntu 12.04
Linux version 3.2.0-29-generic-pae (buildd@roseapple) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) ) #46-Ubuntu SMP Fri Jul 27 17:25:43 UTC 2012

After libcppunit.so is successfully built it turns out that it could not be used due to lack of references. Simple 'make' command fails. Last command is:
g++ -g -O2 -o .libs/DllPlugInTester DllPlugInTester.o CommandLineParser.o -ldl ../../src/cppunit/.libs/libcppunit.so -lm -Wl,--rpath -Wl,/home/tools/cppunit/lib
../../src/cppunit/.libs/libcppunit.so: undefined reference to `dlsym'
../../src/cppunit/.libs/libcppunit.so: undefined reference to `dlopen'
../../src/cppunit/.libs/libcppunit.so: undefined reference to `dlclose'

The error is obviously caused by lack of -ldl option when linking libcppunit.so:

g++ -shared -nostdlib /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crti.o /usr/lib/gcc/i686-linux-gnu/4.6/crtbeginS.o .libs/AdditionalMessage.o .libs/Asserter.o .libs/BeOsDynamicLibraryManager.o .libs/BriefTestProgressListener.o .libs/CompilerOutputter.o .libs/DefaultProtector.o .libs/DynamicLibraryManager.o .libs/DynamicLibraryManagerException.o .libs/Exception.o .libs/Message.o .libs/RepeatedTest.o .libs/PlugInManager.o .libs/PlugInParameters.o .libs/Protector.o .libs/ProtectorChain.o .libs/SourceLine.o .libs/StringTools.o .libs/SynchronizedObject.o .libs/Test.o .libs/TestAssert.o .libs/TestCase.o .libs/TestCaseDecorator.o .libs/TestComposite.o .libs/TestDecorator.o .libs/TestFactoryRegistry.o .libs/TestFailure.o .libs/TestLeaf.o .libs/TestNamer.o .libs/TestPath.o .libs/TestPlugInDefaultImpl.o .libs/TestResult.o .libs/TestResultCollector.o .libs/TestRunner.o .libs/TestSetUp.o .libs/TestSuccessListener.o .libs/TestSuite.o .libs/TestSuiteBuilderContext.o .libs/TextOutputter.o .libs/TextTestProgressListener.o .libs/TextTestResult.o .libs/TextTestRunner.o .libs/TypeInfoHelper.o .libs/UnixDynamicLibraryManager.o .libs/ShlDynamicLibraryManager.o .libs/XmlDocument.o .libs/XmlElement.o .libs/XmlOutputter.o .libs/XmlOutputterHook.o .libs/Win32DynamicLibraryManager.o -L/usr/lib/gcc/i686-linux-gnu/4.6 -L/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu -L/usr/lib/gcc/i686-linux-gnu/4.6/../../../../lib -L/lib/i386-linux-gnu -L/lib/../lib -L/usr/lib/i386-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/i686-linux-gnu/4.6/../../.. -lstdc++ -lm -lc -lgcc_s /usr/lib/gcc/i686-linux-gnu/4.6/crtendS.o /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crtn.o -Wl,-soname -Wl,libcppunit-1.12.so.1 -o .libs/libcppunit-1.12.so.1.0.0

When I added -ldl and executed it manually, the trouble is resolved.
g++ -shared -nostdlib -ldl /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crti.o /usr/lib/gcc/i686-linux-gnu/4.6/crtbeginS.o .libs/AdditionalMessage.o .libs/Asserter.o .libs/BeOsDynamicLibraryManager.o .libs/BriefTestProgressListener.o .libs/CompilerOutputter.o .libs/DefaultProtector.o .libs/DynamicLibraryManager.o .libs/DynamicLibraryManagerException.o .libs/Exception.o .libs/Message.o .libs/RepeatedTest.o .libs/PlugInManager.o .libs/PlugInParameters.o .libs/Protector.o .libs/ProtectorChain.o .libs/SourceLine.o .libs/StringTools.o .libs/SynchronizedObject.o .libs/Test.o .libs/TestAssert.o .libs/TestCase.o .libs/TestCaseDecorator.o .libs/TestComposite.o .libs/TestDecorator.o .libs/TestFactoryRegistry.o .libs/TestFailure.o .libs/TestLeaf.o .libs/TestNamer.o .libs/TestPath.o .libs/TestPlugInDefaultImpl.o .libs/TestResult.o .libs/TestResultCollector.o .libs/TestRunner.o .libs/TestSetUp.o .libs/TestSuccessListener.o .libs/TestSuite.o .libs/TestSuiteBuilderContext.o .libs/TextOutputter.o .libs/TextTestProgressListener.o .libs/TextTestResult.o .libs/TextTestRunner.o .libs/TypeInfoHelper.o .libs/UnixDynamicLibraryManager.o .libs/ShlDynamicLibraryManager.o .libs/XmlDocument.o .libs/XmlElement.o .libs/XmlOutputter.o .libs/XmlOutputterHook.o .libs/Win32DynamicLibraryManager.o -L/usr/lib/gcc/i686-linux-gnu/4.6 -L/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu -L/usr/lib/gcc/i686-linux-gnu/4.6/../../../../lib -L/lib/i386-linux-gnu -L/lib/../lib -L/usr/lib/i386-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/i686-linux-gnu/4.6/../../.. -lstdc++ -lm -lc -lgcc_s /usr/lib/gcc/i686-linux-gnu/4.6/crtendS.o /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crtn.o -Wl,-soname -Wl,libcppunit-1.12.so.1 -o .libs/libcppunit-1.12.so.1.0.0

It's probably the Makefile's deal.

Discussion

  • I 'fixed' this by changing line 21585 of 'configure' from this:

    LIBS="$LIBS -lm"

    to this:

    LIBS="$LIBS -lm -ldl"

     
  • Boinst
    Boinst
    2013-05-24

    I had this problem too. I solved it by adding LDFLAGS="-ldl" to the command line when calling "./configure"

    Like you, I'm also building cppunit 1.12.1 on ubuntu 12.04.

     
    Last edit: Boinst 2013-05-24