<div dir="ltr"><div>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</div><div></div><div><pre><code>APPBASE=/home/AB/Documents/APP/APP_2.17.0
OPENSSL1.0.2p_INSTALL_LOC=/home/AB/Documents/APP/OpenSSL-1.0.2p-installation
CC=gcc
CFLAGS= -Wall -g -O -fPIC
RM= rm -f
.PHONY: all clean

src=$(wildcard *Generic/*.c *Linux/*.c)
$(info source=$(src))

#we use the custom compiled openssl version
#and NOT the one available on the system
#INC=-I/usr/include/openssl
INC+=-I$(OPENSSL1.0.2p_INSTALL_LOC)/include/openssl
INC+=$(foreach d,$(incdir),-I$d)
$(info includes=$(INC))

LIB=-L$(OPENSSL1.0.2p_INSTALL_LOC)/lib
#LIB=-llibssl -llibcrypto
LIB+=-lssl -lcrypto
$(info links=$(LIB))
#LIB+=-L/usr/lib/

obj=$(src:.c=.o)
all: libAPP.so
clean:
    $(RM) *.o *.so
    $(shell find $(APPBASE) -type f -iname "*.o" -exec rm -rf {} \;)

.c.o:
    ${CC} -static ${CFLAGS} $(INC) -c $< $(LIB) -o $@

libAPP.so: $(obj)
    $(LINK.c) -shared $^ -o $@
</code></pre></div><div>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:</div><div><code>-lcrypto -lz -ldl -static-libgcc</code></div><div><code><br></code></div><div><code>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</code></div><div><code><br></code></div><div><code><code>nm libAPP.so | grep -i "ssl" | wc -l</code></code></div><div><code><code>87</code></code></div><div><code><code><br></code></code></div><div><code><code>whereas listing <em>only</em> the global symbols from <code>libssl.a</code> tells me it has 1113 globally defined symbols.</code></code></div><div><code><code><code>nm -g ../OpenSSL-1.0.2p-installation/lib/libssl.a | grep -i "ssl" | wc -l <br></code></code></code></div><div><code><code><code>1113</code></code></code></div><div><code><code><code><br></code></code></code></div><div><code><code><code>I do not know if libSSL got indeed linked statically or not. Could someone please shed some light on it?<br></code></code></code></div><div><code><br></code></div><div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><br>Best Regards,<div>Aijaz Baig</div></div></div></div></div>