简体   繁体   English

静态包含 openssl/libcrypto

[英]Include openssl/libcrypto statically

I am trying to compile an app with static curl and i it seems OpenSSL is not properly linked.我正在尝试使用 static curl 编译一个应用程序,我似乎OpenSSL没有正确链接。

COMPILE CMD:编译 CMD:

$(CXX) $(CXXFLAGS) program1.cpp /opt/curl-7.62.0/lib/libcurl.a /opt/openssl-1.1.1a/lib/libcrypto.a -o program1 -L/opt/curl-7.62.0/ -L/opt/openssl-1.1.1a/ -Wwrite-strings -fpermissive -static-libstdc++ -lcrypto -lssl -lcurl -Wl,-Bstatic -lidn2 -lrt -lz -Wl,-Bdynamic -ldl -lpthread 

CURL: CURL:

rm -rf /opt/curl-7.62.0/*; ./configure --prefix=/opt/curl-7.62.0 --with-pic --disable-shared --enable-static --with-libidn=/opt/libidn2-2.0.4 --with-ssl=/opt/openssl-1.1.1a --without-librtmp --without-gnutls --without-nss --without-libssh2 --with-zlib=/opt/zlib-1.2.11 --without-winidn --disable-rtsp --disable-ldap --disable-ldaps --disable-ipv6 LIBS=-ldl; make -j 8; make install; ls -al /opt/curl-7.62.0/;

OPENSSL: OPENSSL:

./config --prefix=/opt/openssl-1.1.1a -fPIC -static; make; make install;

Errors:错误:

/opt/curl-7.69.1/lib/libcurl.a(libcurl_la-openssl.o): In function `Curl_ossl_sha256sum':
openssl.c:(.text+0x13c): undefined reference to `EVP_MD_CTX_new'
openssl.c:(.text+0x177): undefined reference to `EVP_MD_CTX_free'
/opt/curl-7.69.1/lib/libcurl.a(libcurl_la-openssl.o): In function `Curl_ossl_md5sum':
openssl.c:(.text+0x1cc): undefined reference to `EVP_MD_CTX_new'
openssl.c:(.text+0x207): undefined reference to `EVP_MD_CTX_free'
/opt/curl-7.69.1/lib/libcurl.a(libcurl_la-openssl.o): In function `Curl_ossl_version':
openssl.c:(.text+0xb54): undefined reference to `OpenSSL_version_num'
/opt/curl-7.69.1/lib/libcurl.a(libcurl_la-openssl.o): In function `servercert':
openssl.c:(.text+0x19d0): undefined reference to `X509_get0_notBefore'
openssl.c:(.text+0x1a2c): undefined reference to `X509_get0_notAfter'
openssl.c:(.text+0x1b29): undefined reference to `OPENSSL_sk_num'
openssl.c:(.text+0x1b7f): undefined reference to `OPENSSL_sk_value'
openssl.c:(.text+0x1c77): undefined reference to `X509_get_X509_PUBKEY'
openssl.c:(.text+0x1caf): undefined reference to `X509_get_X509_PUBKEY'
openssl.c:(.text+0x1f22): undefined reference to `OPENSSL_sk_num'
openssl.c:(.text+0x1fa9): undefined reference to `OPENSSL_sk_value'
openssl.c:(.text+0x207e): undefined reference to `X509_get_version'
openssl.c:(.text+0x21f4): undefined reference to `X509_get_X509_PUBKEY'
openssl.c:(.text+0x2272): undefined reference to `X509_get0_extensions'
openssl.c:(.text+0x227d): undefined reference to `OPENSSL_sk_num'
openssl.c:(.text+0x22f1): undefined reference to `OPENSSL_sk_num'
openssl.c:(.text+0x2303): undefined reference to `OPENSSL_sk_value'
openssl.c:(.text+0x2673): undefined reference to `X509_get0_notBefore'
openssl.c:(.text+0x26cb): undefined reference to `X509_get0_notAfter'
openssl.c:(.text+0x2755): undefined reference to `EVP_PKEY_get0_RSA'
openssl.c:(.text+0x276f): undefined reference to `RSA_get0_key'
openssl.c:(.text+0x2ac5): undefined reference to `ASN1_STRING_get0_data'
openssl.c:(.text+0x2b6c): undefined reference to `EVP_PKEY_get0_DSA'
openssl.c:(.text+0x2b8c): undefined reference to `DSA_get0_pqg'
openssl.c:(.text+0x2b9e): undefined reference to `DSA_get0_key'
openssl.c:(.text+0x2c44): undefined reference to `EVP_PKEY_get0_DH'
openssl.c:(.text+0x2c64): undefined reference to `DH_get0_pqg'
openssl.c:(.text+0x2c76): undefined reference to `DH_get0_key'
openssl.c:(.text+0x2d15): undefined reference to `ASN1_STRING_get0_data'
openssl.c:(.text+0x2d3d): undefined reference to `ASN1_STRING_get0_data'
openssl.c:(.text+0x32aa): undefined reference to `ASN1_STRING_get0_data'
/opt/curl-7.69.1/lib/libcurl.a(libcurl_la-openssl.o): In function `ossl_connect_step2':
openssl.c:(.text+0x3461): undefined reference to `SSL_get_client_random'
openssl.c:(.text+0x3476): undefined reference to `SSL_SESSION_get_master_key'
/opt/curl-7.69.1/lib/libcurl.a(libcurl_la-openssl.o): In function `ossl_connect_step1':
openssl.c:(.text+0x3f51): undefined reference to `TLS_client_method'
openssl.c:(.text+0x40b3): undefined reference to `SSL_CTX_set_options'
openssl.c:(.text+0x545c): undefined reference to `OPENSSL_sk_pop_free'
openssl.c:(.text+0x55fe): undefined reference to `OPENSSL_sk_pop'
openssl.c:(.text+0x5640): undefined reference to `OPENSSL_sk_num'
openssl.c:(.text+0x566c): undefined reference to `OPENSSL_sk_pop_free'
collect2: error: ld returned 1 exit status
Makefile:11: recipe for target 'main' failed
....

What could it be?会是什么呢?

Thank you.谢谢你。

I'm fairly certain that libcurl depends on the SSL/Crypto binaries, not the other way around.我相当确定 libcurl 依赖于 SSL/Crypto 二进制文件,而不是相反。

And I believe the gnu linker doesn't "go back" in the library list to resolve missing symbols, only forward in the list.而且我相信 gnu linker 不会在库列表中“返回”来解决丢失的符号,只会在列表中前进。 Hence, this order of library includes:因此,这个库的顺序包括:

-lcrypto -lssl -lcurl

Should be this:应该是这样的:

-lcurl -lssl -lcrypto 

Another option - redundantly append -lcrypto -lssl and to the end of the build line.另一种选择 - 冗余 append -lcrypto -lssl 并到构建行的末尾。 That is:那是:

$(CXX) $(CXXFLAGS) program1.cpp /opt/curl-7.62.0/lib/libcurl.a /opt/openssl-1.1.1a/lib/libcrypto.a -o program1 -L/opt/curl-7.62.0/ -L/opt/openssl-1.1.1a/ -Wwrite-strings -fpermissive -static-libstdc++ -lcrypto -lssl -lcurl -Wl,-Bstatic -lidn2 -lrt -lz -Wl,-Bdynamic -ldl -lpthread -lcrypto -lssl $(CXX) $(CXXFLAGS) program1.cpp /opt/curl-7.62.0/lib/libcurl.a /opt/openssl-1.1.1a/lib/libcrypto.a -o program1 -L/opt/curl-7.62 .0/ -L/opt/openssl-1.1.1a/ -Wwrite-strings -fpermissive -static-libstdc++ -lcrypto -lssl -lcurl -Wl,-Bstatic -lidn2 -lrt -lz -Wl,-Bdynamic -ldl -lpthread -lcrypto -lssl

If any of the above works, you can experiment with link library order.如果上述任何一项工作,您可以尝试链接库顺序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM