LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-19-2012, 04:30 PM   #1
RileyTheWiley
Member
 
Registered: Dec 2007
Posts: 59

Rep: Reputation: 15
Question 'ld' is not finding symbols in a static library


I am linking some code with a static version of libdl.a (never mind why).
The linker complains it can't find several functions in that library.
The library does appear on the linker command line and it exists in the directory. It contains the function as reported by 'nm'.
I have successfully statically linked the same functions from other code.
One difference is that in this case, the failures are associated with another static library that in it's turn calls the missing functions.

In the working code, I called them directly.

Here is some debug spew for you, in several installments.

The command and error from the linker:

g++ -W -Wall -Wno-unused -D_GNU_SOURCE -DTHREAD_SAFE -D_REENTRANT -s -O2 -m64 -fvisibility=hidden -g -Xlinker -rpath -Xlinker /opt/microsoft/scx/lib -Xlinker -rpath-link -Xlinker /home/rdw/dev/om/main/intermediate/Linux_REDHAT_5.0_x64_64_Release/pegasus/lib -o /home/rdw/dev/om/main/intermediate/Linux_REDHAT_5.0_x64_64_Release/pegasus/bin/cimmof /home/rdw/dev/om/main/intermediate/Linux_REDHAT_5.0_x64_64_Release/pegasus/obj/Pegasus/Compiler/cmdline/cimmof/main.o /home/rdw/dev/om/main/intermediate/Linux_REDHAT_5.0_x64_64_Release/pegasus/obj/Pegasus/Compiler/cmdline/cimmof/cmdline.o /home/rdw/dev/om/main/intermediate/Linux_REDHAT_5.0_x64_64_Release/pegasus/obj/Pegasus/Compiler/cmdline/cimmof/cmdlineExceptions.o /home/rdw/dev/om/main/intermediate/Linux_REDHAT_5.0_x64_64_Release/pegasus/lib/libpegcompiler.*[1a] /home/rdw/dev/om/main/intermediate/Linux_REDHAT_5.0_x64_64_Release/pegasus/lib/libpegclient.*[1a] /home/rdw/dev/om/main/intermediate/Linux_REDHAT_5.0_x64_64_Release/pegasus/lib/libpeggetoopt.*[1a] /home/rdw/dev/om/main/intermediate/Linux_REDHAT_5.0_x64_64_Release/pegasus/lib/libpegrepository.*[1a] /home/rdw/dev/om/main/intermediate/Linux_REDHAT_5.0_x64_64_Release/pegasus/lib/libpegconfig.*[1a] /home/rdw/dev/om/main/intermediate/Linux_REDHAT_5.0_x64_64_Release/pegasus/lib/libpegcommon.*[1a] -static /usr/lib64/libdl.a /usr/lib64/libssl.a /usr/lib64/libpthread.a /usr/lib64/libcrypto.a /usr/lib64/libcrypt.a /usr/lib64/libkrb5.a /usr/lib64/libkrb5support.a /usr/lib64/libgssapi_krb5.a /usr/lib64/libz.a /usr/lib64/libk5crypto.a /usr/lib64/libcom_err.a /usr/lib64/libresolv.a
/home/rdw/dev/om/main/intermediate/Linux_REDHAT_5.0_x64_64_Release/pegasus/lib/libpegcommon.a(System.o): In function `Pegasus::System::changeUserContext_SingleThreaded(char const*, unsigned int const&, unsigned int const&)':
/home/rdw/dev/om/main/source/ext/common/pegasus/src/Pegasus/Common/SystemPOSIX.cpp:881: warning: Using 'initgroups' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/rdw/dev/om/main/intermediate/Linux_REDHAT_5.0_x64_64_Release/pegasus/lib/libpegcommon.a(System.o): In function `Pegasus::System::isGroupMember(char const*, char const*)':
/home/rdw/dev/om/main/source/ext/common/pegasus/src/Pegasus/Common/SystemPOSIX.cpp:689: warning: Using 'getgrgid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/rdw/dev/om/main/source/ext/common/pegasus/src/Pegasus/Common/SystemPOSIX.cpp:712: warning: Using 'getgrnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/rdw/dev/om/main/intermediate/Linux_REDHAT_5.0_x64_64_Release/pegasus/lib/libpegcommon.a(FileSystem.o): In function `Pegasus::FileSystem::changeFileOwner(Pegasus::String const&, Pegasus::String const&)':
/home/rdw/dev/om/main/source/ext/common/pegasus/src/Pegasus/Common/FileSystem.cpp:545: warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/rdw/dev/om/main/intermediate/Linux_REDHAT_5.0_x64_64_Release/pegasus/lib/libpegcommon.a(System.o): In function `Pegasus::_initPrivilegedUserName()':
/home/rdw/dev/om/main/source/ext/common/pegasus/src/Pegasus/Common/SystemPOSIX.cpp:627: warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/rdw/dev/om/main/intermediate/Linux_REDHAT_5.0_x64_64_Release/pegasus/lib/libpegcommon.a(System.o): In function `Pegasus::System::getAddrInfo(char const*, char const*, addrinfo const*, addrinfo**)':
/home/rdw/dev/om/main/source/ext/common/pegasus/src/Pegasus/Common/System.cpp:937: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/rdw/dev/om/main/intermediate/Linux_REDHAT_5.0_x64_64_Release/pegasus/lib/libpegcommon.a(System.o): In function `Pegasus::System::getHostByAddr(char const*, int, int, hostent*, char*, unsigned long)':
/home/rdw/dev/om/main/source/ext/common/pegasus/src/Pegasus/Common/System.cpp:891: warning: Using 'gethostbyaddr_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/rdw/dev/om/main/intermediate/Linux_REDHAT_5.0_x64_64_Release/pegasus/lib/libpegcommon.a(System.o): In function `Pegasus::System::getHostByName(char const*, hostent*, char*, unsigned long)':
/home/rdw/dev/om/main/source/ext/common/pegasus/src/Pegasus/Common/System.cpp:839: warning: Using 'gethostbyname_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib64/libkrb5.a(locate_kdc.o): In function `krb5int_locate_server':
(.text+0x970): warning: Using 'getservbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/rdw/dev/om/main/intermediate/Linux_REDHAT_5.0_x64_64_Release/pegasus/lib/libpegcommon.a(System.o): In function `Pegasus::System::lookupPort(char const*, unsigned int)':
/home/rdw/dev/om/main/source/ext/common/pegasus/src/Pegasus/Common/SystemPOSIX.cpp:270: warning: Using 'getservbyname_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib64/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
(.text+0x174): undefined reference to `dlsym'
/usr/lib64/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
(.text+0x22c): undefined reference to `dlerror'
/usr/lib64/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_var':
(.text+0x2a4): undefined reference to `dlsym'
/usr/lib64/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_var':
(.text+0x35c): undefined reference to `dlerror'
/usr/lib64/libcrypto.a(dso_dlfcn.o): In function `dlfcn_unload':
(.text+0x3bd): undefined reference to `dlclose'
/usr/lib64/libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':
(.text+0x472): undefined reference to `dlopen'
/usr/lib64/libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':
(.text+0x4dd): undefined reference to `dlclose'
/usr/lib64/libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':
(.text+0x507): undefined reference to `dlerror'
/usr/lib64/libkrb5support.a(plugins.o): In function `krb5int_close_plugin':
(.text+0x10d): undefined reference to `dlclose'
/usr/lib64/libkrb5support.a(plugins.o): In function `krb5int_get_plugin_sym':
(.text+0x1a1): undefined reference to `dlsym'
/usr/lib64/libkrb5support.a(plugins.o): In function `krb5int_get_plugin_sym':
(.text+0x1b3): undefined reference to `dlerror'
/usr/lib64/libkrb5support.a(plugins.o): In function `krb5int_open_plugin':
(.text+0x5c9): undefined reference to `dlopen'
/usr/lib64/libkrb5support.a(plugins.o): In function `krb5int_open_plugin':
(.text+0x616): undefined reference to `dlerror'
collect2: ld returned 1 exit status


Here is the 'nm' output that proves that symbol is present in the (T)ext section:


rdw@xxxomd64-cent5-01:mak> nm /usr/lib64/*.a --print-file-name 2>&1| grep dlsym | grep T
/usr/lib64/libc.a:sdlsym.o:0000000000000000 T __dlsym
/usr/lib64/libc.a:dl-libc.o:0000000000000170 T __libc_dlsym
/usr/lib64/libc.a:dl-libc.o:00000000000001e0 T __libc_dlsym_private
/usr/lib64/libdl.a:dlsym.o:0000000000000000 T dlsym
/usr/lib64/libsmbclient.a:system.po:0000000000000300 T sys_dlsym


So why isn't 'ld' finding that symbol?

RDeW
 
Old 04-20-2012, 09:11 AM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
The ordering of the libraries matters. Try placing /usr/lib64/libdl.a after /usr/lib64/libcrypto.a. Also, you have warnings that essentially say that you need to link to the shared version of glibc for libdl to work.
Kevin Barry
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Linker not finding symbols, but library and link command look ok darenw Linux - Software 8 05-31-2010 01:08 AM
'nm' lists all symbols - including static library symbols painulyarun Programming 4 04-06-2010 04:04 AM
Debugger selectively not using symbols in library with symbols Millenniumman Programming 1 03-03-2007 07:46 PM
Hiding global symbols in a shared/static library jineshkj Programming 16 08-30-2006 12:45 AM


All times are GMT -5. The time now is 11:04 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration