JezK
Edit File: linker.library.check.html
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Checking if a Library Provides a Function</title><link rel="stylesheet" type="text/css" href="userguide.css" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="home" href="index.html" title="FreeTDS User Guide" /><link rel="up" href="rtl.html" title="Appendix A. On Linkers" /><link rel="prev" href="rtl.define.library.html" title="What is a C library?" /><link rel="next" href="linker.how.html" title="How Dost Thy Linker Link?" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Checking if a Library Provides a Function</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="rtl.define.library.html">Prev</a> </td><th width="60%" align="center">Appendix A. On Linkers</th><td width="20%" align="right"> <a accesskey="n" href="linker.how.html">Next</a></td></tr></table><hr /></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="linker.library.check"></a>Checking if a Library Provides a Function</h2></div></div></div><p>A linker, any linker, knits together object files (some of which may be in libraries) such that every function needed by the program has a definition. If the linker fails to locate a definition for even one function, it will fail and the program will not run. </p><p>Returning to <a class="link" href="rtl.html#bsqldb.unresolved"><code class="filename">bsqldb.o</code></a>, we can use <span class="command"><strong>nm</strong></span> to see which functions are unresolved, and determine whether or not a particular library contains them. We'll ignore the symbols that start with an underscore, marking them per the C standard as being provided by the implementation<a href="#ftn.idm6649" class="footnote" id="idm6649"><sup class="footnote">[36]</sup></a>, and focus on the last five in this abbreviated list. </p><div class="variablelist"><p class="title"><strong>Some unresolved functions in <code class="filename">bsqldb.o</code></strong></p><dl class="variablelist"><dt><span class="term"><code class="function">asprintf</code>, </span><span class="term"><code class="function">basename</code></span></dt><dd><p>Normally provided by the standard C library, but if not by <span class="productname">FreeTDS</span>'s replacements library: </p><pre class="screen"><code class="prompt">$ </code><strong class="userinput"><code>nm /usr/lib/libc.a | grep -w T | grep -E 'asprintf|basename' </code></strong> <code class="computeroutput">0000000000000000 T _basename 0000000000000000 T _asprintf</code> </pre><p> </p></dd><dt><span class="term"><code class="function">calloc</code></span></dt><dd><p>Provided by the standard C library: </p><pre class="screen"><code class="prompt">$ </code><strong class="userinput"><code>nm /usr/lib/libc.a | grep -w T | grep calloc </code></strong> <code class="computeroutput">0000000000004240 T calloc</code> </pre><p> </p></dd><dt><span class="term"><code class="function">dbaltbind</code>, </span><span class="term"><code class="function">dbaltcolid</code></span></dt><dd><p>Provided by <code class="systemitem">DB-Library</code>: </p><pre class="screen"><code class="prompt">$ </code><strong class="userinput"><code>nm libsybdb.a | grep -Ew 'dbaltbind|dbaltcolid'</code></strong> <code class="computeroutput">0000000000007140 T dbaltbind 0000000000003590 T dbaltcolid</code> </pre><p> </p></dd></dl></div><p> Although these examples refer to static libraries, <span class="command"><strong>nm</strong></span> works just as well with dynamic libraries, too. </p><p>There are other tools besides <span class="command"><strong>nm</strong></span>. Windows®, for instance, has <span class="command"><strong>dumpbin</strong></span>, and the GNU bintools include <span class="command"><strong>objdump</strong></span>. </p><div class="footnotes"><br /><hr style="width:100; text-align:left;margin-left: 0" /><div id="ftn.idm6649" class="footnote"><p><a href="#idm6649" class="para"><sup class="para">[36] </sup></a>Why and how leading underscores enter into this discussion is just one more example of arcane historical practices one needs to know to master the subject. For our purposes, though, it's enough to know that <span class="quote">“<span class="quote">implementation-provided</span>”</span> functions like these — functions provided by the C standard library — often have an underscored prepended. </p></div></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="rtl.define.library.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="rtl.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="linker.how.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">What is a C library? </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> How Dost Thy Linker Link? </td></tr></table></div></body></html>