<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"MS Mincho";
        panose-1:2 2 6 9 4 2 5 8 3 4;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
        {font-family:"\@MS Mincho";
        panose-1:0 0 0 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
code
        {mso-style-priority:99;
        font-family:"Courier New";}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;}
span.EmailStyle21
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">To check if you are linked statically or dynamically, what does ldd tell you? (</span><code><span style="font-size:10.0pt">ldd libAPP.so</span></code><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">)
 Your library should not have a dependency on libssl.so or libcrypto.so if you are linked statically.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">-Tom<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> openssl-users [mailto:openssl-users-bounces@openssl.org]
<b>On Behalf Of </b>Aijaz Baig<br>
<b>Sent:</b> Sunday, November 3, 2019 11:30 PM<br>
<b>To:</b> openssl-users@openssl.org<br>
<b>Subject:</b> static linking libssl and libcrypto<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">I am trying to build a shared library that internally links openssl and crypto libraries statically so I can use it in a production environment. To that end I am using the following Makefile<o:p></o:p></p>
</div>
<div>
<pre><code>APPBASE=/home/AB/Documents/APP/APP_2.17.0<o:p></o:p></code></pre>
<pre><code>OPENSSL1.0.2p_INSTALL_LOC=/home/AB/Documents/APP/OpenSSL-1.0.2p-installation<o:p></o:p></code></pre>
<pre><code>CC=gcc<o:p></o:p></code></pre>
<pre><code>CFLAGS= -Wall -g -O -fPIC<o:p></o:p></code></pre>
<pre><code>RM= rm -f<o:p></o:p></code></pre>
<pre><code>.PHONY: all clean<o:p></o:p></code></pre>
<pre><code><o:p> </o:p></code></pre>
<pre><code>src=$(wildcard *Generic/*.c *Linux/*.c)<o:p></o:p></code></pre>
<pre><code>$(info source=$(src))<o:p></o:p></code></pre>
<pre><code><o:p> </o:p></code></pre>
<pre><code>#we use the custom compiled openssl version<o:p></o:p></code></pre>
<pre><code>#and NOT the one available on the system<o:p></o:p></code></pre>
<pre><code>#INC=-I/usr/include/openssl<o:p></o:p></code></pre>
<pre><code>INC+=-I$(OPENSSL1.0.2p_INSTALL_LOC)/include/openssl<o:p></o:p></code></pre>
<pre><code>INC+=$(foreach d,$(incdir),-I$d)<o:p></o:p></code></pre>
<pre><code>$(info includes=$(INC))<o:p></o:p></code></pre>
<pre><code><o:p> </o:p></code></pre>
<pre><code>LIB=-L$(OPENSSL1.0.2p_INSTALL_LOC)/lib<o:p></o:p></code></pre>
<pre><code>#LIB=-llibssl -llibcrypto<o:p></o:p></code></pre>
<pre><code>LIB+=-lssl -lcrypto<o:p></o:p></code></pre>
<pre><code>$(info links=$(LIB))<o:p></o:p></code></pre>
<pre><code>#LIB+=-L/usr/lib/<o:p></o:p></code></pre>
<pre><code><o:p> </o:p></code></pre>
<pre><code>obj=$(src:.c=.o)<o:p></o:p></code></pre>
<pre><code>all: libAPP.so<o:p></o:p></code></pre>
<pre><code>clean:<o:p></o:p></code></pre>
<pre><code>    $(RM) *.o *.so<o:p></o:p></code></pre>
<pre><code>    $(shell find $(APPBASE) -type f -iname "*.o" -exec rm -rf {} \;)<o:p></o:p></code></pre>
<pre><code><o:p> </o:p></code></pre>
<pre><code>.c.o:<o:p></o:p></code></pre>
<pre><code>    ${CC} -static ${CFLAGS} $(INC) -c $< $(LIB) -o $@<o:p></o:p></code></pre>
<pre><code><o:p> </o:p></code></pre>
<pre><code>libAPP.so: $(obj)<o:p></o:p></code></pre>
<pre><code>    $(LINK.c) -shared $^ -o $@<o:p></o:p></code></pre>
</div>
<div>
<p class="MsoNormal">As mentioned here (<a href="https://stackoverflow.com/questions/18185618/how-to-use-static-linking-with-openssl-in-c-c/25811538#25811538">https://stackoverflow.com/questions/18185618/how-to-use-static-linking-with-openssl-in-c-c/25811538#25811538</a>),
 I've changed the linker flags to:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10.0pt">-lcrypto -lz -ldl -static-libgcc</span></code><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10.0pt">but it doesn't seem to change the size of the generated so file. On checking for references to SSL in this so file, I see there are a total of 87 entries</span></code><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10.0pt">nm libAPP.so | grep -i "ssl" | wc -l</span></code><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10.0pt">87</span></code><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10.0pt">whereas listing </span>
</code><em><span style="font-size:10.0pt;font-family:"Courier New"">only</span></em><code><span style="font-size:10.0pt"> the global symbols from libssl.a tells me it has 1113 globally defined symbols.</span></code><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10.0pt">nm -g ../OpenSSL-1.0.2p-installation/lib/libssl.a | grep -i "ssl" | wc -l
</span></code><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10.0pt">1113</span></code><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10.0pt">I do not know if libSSL got indeed linked statically or not. Could someone please shed some light on it?</span></code><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">-- <o:p></o:p></p>
<div>
<div>
<p class="MsoNormal"><br>
Best Regards,<o:p></o:p></p>
<div>
<p class="MsoNormal">Aijaz Baig<o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>