openssl静态库使用出错undefined reference to `COMP_CTX_new'

有个项目又要用到openssl,在Linux下编译的时候没注意,报了以下错误

libcrypto.a(threads_pthread.o): In function `fork_once_func':
threads_pthread.c:(.text+0x76): undefined reference to `pthread_atfork'
libssl.a(ssl3_record.o): In function `ssl3_do_compress':
ssl3_record.c:(.text+0x17af): undefined reference to `COMP_compress_block'
libssl.a(ssl3_record.o): In function `ssl3_do_uncompress':
ssl3_record.c:(.text+0x180a): undefined reference to `COMP_expand_block'
libssl.a(ssl_cert.o): In function `ssl_build_cert_chain':
ssl_cert.c:(.text+0x6e1): undefined reference to `X509_verify_cert_error_string'
libssl.a(ssl_cert.o): In function `SSL_add_file_cert_subjects_to_stack':
ssl_cert.c:(.text+0x953): undefined reference to `PEM_read_bio_X509'
libssl.a(ssl_cert.o): In function `SSL_load_client_CA_file':
ssl_cert.c:(.text+0xe4b): undefined reference to `PEM_read_bio_X509'
libssl.a(ssl_ciph.o): In function `SSL_COMP_add_compression_method':
ssl_ciph.c:(.text+0x965): undefined reference to `COMP_get_type'
libssl.a(ssl_ciph.o): In function `do_load_builtin_compressions_ossl_':
ssl_ciph.c:(.text+0xb3f): undefined reference to `COMP_get_type'
ssl_ciph.c:(.text+0xb7d): undefined reference to `COMP_get_name'
libssl.a(ssl_ciph.o): In function `ssl_cipher_get_evp':
ssl_ciph.c:(.text+0x28bf): undefined reference to `EVP_enc_null'
libssl.a(ssl_ciph.o): In function `SSL_COMP_get_name':
ssl_ciph.c:(.text+0x8d6): undefined reference to `COMP_get_name'
libssl.a(ssl_lib.o): In function `SSL_get0_peer_scts':
ssl_lib.c:(.text+0x2a77): undefined reference to `OCSP_response_get1_basic'
ssl_lib.c:(.text+0x2a9f): undefined reference to `OCSP_resp_count'
ssl_lib.c:(.text+0x2ab1): undefined reference to `OCSP_resp_get0'
ssl_lib.c:(.text+0x2ac7): undefined reference to `OCSP_SINGLERESP_get1_ext_d2i'
libssl.a(ssl_lib.o): In function `ssl_validate_ct':
ssl_lib.c:(.text+0x2bb0): undefined reference to `CT_POLICY_EVAL_CTX_new'
ssl_lib.c:(.text+0x2bdb): undefined reference to `CT_POLICY_EVAL_CTX_set1_cert'
ssl_lib.c:(.text+0x2be6): undefined reference to `CT_POLICY_EVAL_CTX_set1_issuer'
ssl_lib.c:(.text+0x2bfc): undefined reference to `CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE'
ssl_lib.c:(.text+0x2c1b): undefined reference to `CT_POLICY_EVAL_CTX_set_time'
ssl_lib.c:(.text+0x2c5b): undefined reference to `CT_POLICY_EVAL_CTX_free'
ssl_lib.c:(.text+0x2cb8): undefined reference to `CT_POLICY_EVAL_CTX_free'
libssl.a(ssl_lib.o): In function `SSL_CTX_set_default_verify_file':
ssl_lib.c:(.text+0x31e5): undefined reference to `X509_LOOKUP_file'
libssl.a(ssl_lib.o): In function `SSL_CTX_set_default_verify_dir':
ssl_lib.c:(.text+0x3225): undefined reference to `X509_LOOKUP_hash_dir'
libssl.a(ssl_lib.o): In function `ssl_clear_cipher_ctx':
ssl_lib.c:(.text+0x34e4): undefined reference to `COMP_CTX_free'
ssl_lib.c:(.text+0x34fb): undefined reference to `COMP_CTX_free'
libssl.a(ssl_lib.o): In function `SSL_CTX_load_verify_locations':
ssl_lib.c:(.text+0x31d5): undefined reference to `X509_STORE_load_locations'
libssl.a(ssl_lib.o): In function `SSL_CTX_set_default_verify_paths':
ssl_lib.c:(.text+0x3265): undefined reference to `X509_STORE_set_default_paths'
libssl.a(ssl_lib.o): In function `SSL_get_current_expansion':
ssl_lib.c:(.text+0x346d): undefined reference to `COMP_CTX_get_method'
libssl.a(ssl_lib.o): In function `SSL_get_current_compression':
ssl_lib.c:(.text+0x348d): undefined reference to `COMP_CTX_get_method'
libssl.a(ssl_rsa.o): In function `SSL_CTX_use_RSAPrivateKey_file':
ssl_rsa.c:(.text+0x16e6): undefined reference to `PEM_read_bio_RSAPrivateKey'
libssl.a(ssl_rsa.o): In function `SSL_use_RSAPrivateKey_file':
ssl_rsa.c:(.text+0x19e6): undefined reference to `PEM_read_bio_RSAPrivateKey'
libssl.a(ssl_rsa.o): In function `SSL_CTX_use_certificate_file':
ssl_rsa.c:(.text+0x1ebe): undefined reference to `PEM_read_bio_X509'
libssl.a(ssl_rsa.o): In function `use_certificate_chain_file':
ssl_rsa.c:(.text+0x2094): undefined reference to `PEM_read_bio_X509_AUX'
ssl_rsa.c:(.text+0x2106): undefined reference to `PEM_read_bio_X509'
ssl_rsa.c:(.text+0x219d): undefined reference to `PEM_read_bio_X509'
libssl.a(ssl_rsa.o): In function `SSL_use_certificate_file':
ssl_rsa.c:(.text+0x241e): undefined reference to `PEM_read_bio_X509'
libssl.a(t1_lib.o): In function `ssl_get_auto_dh':
t1_lib.c:(.text+0xcbb): undefined reference to `BN_get_rfc3526_prime_8192'
t1_lib.c:(.text+0xd13): undefined reference to `BN_get_rfc3526_prime_3072'
libssl.a(tls_srp.o): In function `SRP_Calc_A_param':
tls_srp.c:(.text+0x1bc): undefined reference to `SRP_Calc_A'
libssl.a(tls_srp.o): In function `srp_verify_server_param':
tls_srp.c:(.text+0x2b9): undefined reference to `SRP_check_known_gN_param'
libssl.a(tls_srp.o): In function `srp_generate_client_master_secret':
tls_srp.c:(.text+0x326): undefined reference to `SRP_Verify_B_mod_N'
tls_srp.c:(.text+0x348): undefined reference to `SRP_Calc_u'
tls_srp.c:(.text+0x392): undefined reference to `SRP_Calc_x'
tls_srp.c:(.text+0x3c5): undefined reference to `SRP_Calc_client_key'
libssl.a(tls_srp.o): In function 
libssl.a(tls_srp.o): In function `srp_generate_server_master_secret':
tls_srp.c:(.text+0x56f): undefined reference to `SRP_Verify_A_mod_N'
tls_srp.c:(.text+0x5d6): undefined reference to `SRP_Calc_u'
tls_srp.c:(.text+0x602): undefined reference to `SRP_Calc_server_key'
libssl.a(tls_srp.o): In function `SSL_set_srp_server_param_pw':
tls_srp.c:(.text+0x905): undefined reference to `SRP_get_default_gN'
tls_srp.c:(.text+0x9a3): undefined reference to `SRP_create_verifier_BN'
libssl.a(tls_srp.o): In function `SSL_srp_server_param_with_username':
tls_srp.c:(.text+0xa77): undefined reference to `SRP_Calc_B'
libssl.a(s3_enc.o): In function `ssl3_change_cipher_state':
s3_enc.c:(.text+0xf76): undefined reference to `COMP_CTX_free'
s3_enc.c:(.text+0xf8e): undefined reference to `COMP_CTX_new'
s3_enc.c:(.text+0x1166): undefined reference to `COMP_CTX_free'
s3_enc.c:(.text+0x117e): undefined reference to `COMP_CTX_new'
libssl.a(ssl_conf.o): In function `cmd_ChainCAFile':
ssl_conf.c:(.text+0x954): undefined reference to `X509_STORE_load_locations'
libssl.a(ssl_conf.o): In function `cmd_VerifyCAFile':
ssl_conf.c:(.text+0x1b14): undefined reference to `X509_STORE_load_locations'
libssl.a(ssl_conf.o): In function `cmd_ChainCAPath':
ssl_conf.c:(.text+0x1ba7): undefined reference to `X509_STORE_load_locations'
libssl.a(ssl_conf.o): In function `cmd_VerifyCAPath':
ssl_conf.c:(.text+0x1c37): undefined reference to `X509_STORE_load_locations'
libssl.a(t1_enc.o): In function `tls1_change_cipher_state':
t1_enc.c:(.text+0xd2): undefined reference to `COMP_CTX_free'
t1_enc.c:(.text+0xeb): undefined reference to `COMP_CTX_new'
t1_enc.c:(.text+0x236): undefined reference to `COMP_CTX_free'
t1_enc.c:(.text+0x24f): undefined reference to `COMP_CTX_new'
collect2: ld 返回1

以前都在用怎么就不行了,后来发现自己在加载库的时候顺序反了;

解决方案

先加载libssl 再加载libcrypto.a

-L. libssl.a libcrypto

你可能感兴趣的:(C/C++,linux)