How to use static linking with OpenSSL in C/C++

只愿长相守 提交于 2019-11-30 11:56:32
user4035357

I had a similar issue trying to statically compile a simple DES program using the openssl lib. I used -lcrypto -lz -ldl -static-libgcc and it worked for me. No warnings or errors.

You need to be aware that libraries need to availiable as statically linked *.a files. If they are not, then compilation will either fail or you end up with a dynamically linked executable.

If this gets too much PITA (all the libraries dependencies need to be statically compiled to, and their deps too and so on) use something like buildroot

A hotfix: try to link in libdl statically, too.

If this not works, IMHO your libcrypto.a is bad compiled.

I had the same problem as you. Here's the command that solved it for me:

gcc yourfile.c -o yourfile -static -lcrypto -lz -ldl

It generates this warning:

/usr/lib/gcc/i686-linux-gnu/4.7/../../../i386-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup': (.text+0x1b): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

but the executable still works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!