0

I am trying to compile an statically-linked executable, but I cannot seem to avoid producing a dynamically-linked one instead. I tried this compilation command first:

gcc -o test test.c -lcrypto -ldl -lz -static-libgcc 

I have also tried just -static and --disable-shared with the same results. I thought the above command would be enough to produce a static executable, but the file command tells me that the result is dynamically linked.

Can anyone shed some light on what I am doing wrong?

John Bollinger
  • 160,171
  • 8
  • 81
  • 157
akfe79
  • 59
  • 1
  • 1
  • 5
  • 2
    http://stackoverflow.com/questions/3283021/compile-a-standalone-static-executable – Module Aug 02 '16 at 19:51
  • 1
    Do you have static versions of libcrypto, libdl, and libz installed? – John Bollinger Aug 02 '16 at 20:00
  • You should definitely use the `-static` flag in addition to `-static-libgcc`. To the best of my knowledge, the latter does not imply static linking of libraries other than libgcc. – John Bollinger Aug 02 '16 at 20:11
  • I figured out how to compile the executable to be statically linked. The final command was "gcc Test.c ~/openssl/libcrypto.a -lcrypto -ldl -lz -o Test --static -static-libgcc". The final was close to what I had in the question. I just needed to include the path to libcrypto.a. I have marked the question as answered because my question was similar to another question with the exception that I have included OpenSSL. Thanks. – akfe79 Aug 02 '16 at 22:20

0 Answers0