在Linux用libcurl.a在链接的时候出错

本文介绍了解决curl链接时出现未定义引用错误的方法。通过下载curl源码并进行特定配置,禁用LDAP/LDAPS支持,重新编译安装,最终解决了因缺少依赖库导致的链接错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转自: http://www.cnblogs.com/bugutian/p/4868167.html


其实出错是因为curl链接的时候需要别的库。我用如下方法解决

1、http://curl.haxx.se/download/curl-7.45.0.tar.gz官网下载源码

2、./configure --disable-ldap --disable-ldaps

     make

     cp ./lib/.libs/libcurl.a ../pathto/project

3、链接时加参数:-lidn -lrt -lcrypto -lssl

    如:-lidn -lrt -lcrypto -lssl ./lib/libcurl.a

参考:

http://blog.youkuaiyun.com/langeldep/article/details/6223649

http://blog.youkuaiyun.com/pingd/article/details/46120749

附录:错误信息是下面这样的,由于太长,我把解决方法写在上面。

./lib/libcurl.a(libcurl_la-content_encoding.o): In function `exit_zlib':
content_encoding.c:(.text+0x135): undefined reference to `inflateEnd'
./lib/libcurl.a(libcurl_la-content_encoding.o): In function `inflate_stream':
content_encoding.c:(.text+0x24e): undefined reference to `inflate'
content_encoding.c:(.text+0x2b9): undefined reference to `inflateEnd'
content_encoding.c:(.text+0x2d2): undefined reference to `inflateInit2_'
content_encoding.c:(.text+0x361): undefined reference to `inflateEnd'
./lib/libcurl.a(libcurl_la-content_encoding.o): In function `Curl_unencode_gzip_write':
content_encoding.c:(.text+0x468): undefined reference to `zlibVersion'
content_encoding.c:(.text+0x49f): undefined reference to `inflateInit2_'
content_encoding.c:(.text+0x4f5): undefined reference to `inflateInit2_'
./lib/libcurl.a(libcurl_la-content_encoding.o): In function `Curl_unencode_deflate_write':
content_encoding.c:(.text+0x717): undefined reference to `inflateInit_'
./lib/libcurl.a(libcurl_la-openldap.o): In function `ldap_disconnect':
openldap.c:(.text+0x5a): undefined reference to `ldap_unbind_ext'
./lib/libcurl.a(libcurl_la-openldap.o): In function `ldap_connecting':
openldap.c:(.text+0x10e): undefined reference to `ldap_result'
openldap.c:(.text+0x149): undefined reference to `ldap_parse_result'
openldap.c:(.text+0x171): undefined reference to `ldap_get_option'
openldap.c:(.text+0x18b): undefined reference to `ldap_memfree'
openldap.c:(.text+0x1ac): undefined reference to `ldap_set_option'
openldap.c:(.text+0x1ee): undefined reference to `ldap_sasl_bind'
openldap.c:(.text+0x260): undefined reference to `ldap_get_option'
openldap.c:(.text+0x279): undefined reference to `ber_sockbuf_add_io'
openldap.c:(.text+0x2ba): undefined reference to `ldap_err2string'
openldap.c:(.text+0x2e9): undefined reference to `ldap_memfree'
openldap.c:(.text+0x302): undefined reference to `ldap_memfree'
openldap.c:(.text+0x322): undefined reference to `ldap_err2string'
openldap.c:(.text+0x347): undefined reference to `ldap_err2string'
./lib/libcurl.a(libcurl_la-openldap.o): In function `ldap_recv':
openldap.c:(.text+0x4ce): undefined reference to `ldap_result'
openldap.c:(.text+0x4fd): undefined reference to `ldap_first_message'
openldap.c:(.text+0x514): undefined reference to `ldap_msgtype'
openldap.c:(.text+0x52d): undefined reference to `ldap_next_message'
openldap.c:(.text+0x549): undefined reference to `ldap_msgfree'
openldap.c:(.text+0x584): undefined reference to `ldap_get_dn_ber'
openldap.c:(.text+0x621): undefined reference to `ldap_get_attribute_ber'
openldap.c:(.text+0x7f1): undefined reference to `ber_memfree'
openldap.c:(.text+0x905): undefined reference to `ldap_err2string'
openldap.c:(.text+0x933): undefined reference to `ber_memfree'
openldap.c:(.text+0x93f): undefined reference to `ber_free'
openldap.c:(.text+0x94c): undefined reference to `ldap_msgfree'
openldap.c:(.text+0x991): undefined reference to `ber_free'
openldap.c:(.text+0x9cc): undefined reference to `ldap_parse_result'
openldap.c:(.text+0xa00): undefined reference to `ldap_err2string'
openldap.c:(.text+0xa3e): undefined reference to `ldap_memfree'
openldap.c:(.text+0xa7b): undefined reference to `ldap_err2string'
./lib/libcurl.a(libcurl_la-openldap.o): In function `ldap_connect':
openldap.c:(.text+0xb58): undefined reference to `ldap_init_fd'
openldap.c:(.text+0xb63): undefined reference to `ldap_err2string'
openldap.c:(.text+0xbbf): undefined reference to `ldap_set_option'
./lib/libcurl.a(libcurl_la-openldap.o): In function `ldap_done':
openldap.c:(.text+0xc4f): undefined reference to `ldap_abandon_ext'
./lib/libcurl.a(libcurl_la-openldap.o): In function `ldap_do':
openldap.c:(.text+0xcbd): undefined reference to `ldap_url_parse'
openldap.c:(.text+0xd78): undefined reference to `ldap_search_ext'
openldap.c:(.text+0xd85): undefined reference to `ldap_free_urldesc'
openldap.c:(.text+0xdfb): undefined reference to `ldap_err2string'
./lib/libcurl.a(libcurl_la-openldap.o): In function `ldap_setup_connection':
openldap.c:(.text+0xe46): undefined reference to `ldap_url_parse'
openldap.c:(.text+0xe60): undefined reference to `ldap_pvt_url_scheme2proto'
openldap.c:(.text+0xe6c): undefined reference to `ldap_free_urldesc'
./lib/libcurl.a(libcurl_la-openssl.o): In function `Curl_ossl_sha256sum':
openssl.c:(.text+0x38): undefined reference to `SHA256_Init'
openssl.c:(.text+0x46): undefined reference to `SHA256_Update'
openssl.c:(.text+0x51): undefined reference to `SHA256_Final'
./lib/libcurl.a(libcurl_la-openssl.o): In function `Curl_ossl_md5sum':
openssl.c:(.text+0xa8): undefined reference to `MD5_Init'
openssl.c:(.text+0xb6): undefined reference to `MD5_Update'
openssl.c:(.text+0xc1): undefined reference to `MD5_Final'
./lib/libcurl.a(libcurl_la-openssl.o): In function `rand_enough':
openssl.c:(.text+0xf5): undefined reference to `RAND_status'
./lib/libcurl.a(libcurl_la-openssl.o): In function `Curl_ossl_seed':
openssl.c:(.text+0x143): undefined reference to `RAND_load_file'
openssl.c:(.text+0x18d): undefined reference to `RAND_egd'
openssl.c:(.text+0x1ba): undefined reference to `RAND_bytes'
openssl.c:(.text+0x1d2): undefined reference to `RAND_add'
openssl.c:(.text+0x1d7): undefined reference to `RAND_status'
openssl.c:(.text+0x1ed): undefined reference to `RAND_file_name'
openssl.c:(.text+0x201): undefined reference to `RAND_load_file'
./lib/libcurl.a(libcurl_la-openssl.o): In function `Curl_ossl_random':
openssl.c:(.text+0x27c): undefined reference to `RAND_bytes'
./lib/libcurl.a(libcurl_la-openssl.o): In function `Curl_ossl_version':
openssl.c:(.text+0x2b7): undefined reference to `SSLeay'
./lib/libcurl.a(libcurl_la-openssl.o): In function `Curl_ossl_data_pending':
openssl.c:(.text+0x39b): undefined reference to `SSL_pending'
./lib/libcurl.a(libcurl_la-openssl.o): In function `ssl_ui_writer':
openssl.c:(.text+0x430): undefined reference to `UI_get_string_type'
openssl.c:(.text+0x440): undefined reference to `UI_get0_user_data'
openssl.c:(.text+0x44d): undefined reference to `UI_get_input_flags'
openssl.c:(.text+0x456): undefined reference to `UI_OpenSSL'
openssl.c:(.text+0x45e): undefined reference to `UI_method_get_writer'
./lib/libcurl.a(libcurl_la-openssl.o): In function `ssl_ui_reader':
openssl.c:(.text+0x49d): undefined reference to `UI_get_string_type'
openssl.c:(.text+0x4ad): undefined reference to `UI_get0_user_data'
openssl.c:(.text+0x4bd): undefined reference to `UI_get_input_flags'
openssl.c:(.text+0x4c6): undefined reference to `UI_OpenSSL'
openssl.c:(.text+0x4ce): undefined reference to `UI_method_get_reader'
openssl.c:(.text+0x4fa): undefined reference to `UI_set_result'
./lib/libcurl.a(libcurl_la-openssl.o): In function `SSL_strerror':
openssl.c:(.text+0x885): undefined reference to `ERR_error_string_n'
./lib/libcurl.a(libcurl_la-openssl.o): In function `ossl_connect_step2':
openssl.c:(.text+0x8c6): undefined reference to `ERR_clear_error'
openssl.c:(.text+0x8cf): undefined reference to `SSL_connect'
openssl.c:(.text+0x8e3): undefined reference to `SSL_get_error'
openssl.c:(.text+0x91c): undefined reference to `ERR_get_error'
openssl.c:(.text+0x9ce): undefined reference to `SSL_get_current_cipher'
openssl.c:(.text+0x9d6): undefined reference to `SSL_CIPHER_get_name'
openssl.c:(.text+0x9ee): undefined reference to `SSL_version'
openssl.c:(.text+0xa55): undefined reference to `SSL_get_verify_result'
openssl.c:(.text+0xa62): undefined reference to `X509_verify_cert_error_string'
./lib/libcurl.a(libcurl_la-openssl.o): In function `x509_name_oneline':
openssl.c:(.text+0xb37): undefined reference to `BIO_s_mem'
openssl.c:(.text+0xb3f): undefined reference to `BIO_new'
openssl.c:(.text+0xb5e): undefined reference to `X509_NAME_print_ex'
openssl.c:(.text+0xb75): undefined reference to `BIO_ctrl'
openssl.c:(.text+0xba4): undefined reference to `BIO_free'
./lib/libcurl.a(libcurl_la-openssl.o): In function `pubkey_show':
openssl.c:(.text+0xc16): undefined reference to `BN_print'
openssl.c:(.text+0xc2a): undefined reference to `BIO_ctrl'
openssl.c:(.text+0xc51): undefined reference to `BIO_ctrl'
./lib/libcurl.a(libcurl_la-openssl.o): In function `verifyhost':
openssl.c:(.text+0xd02): undefined reference to `X509_get_ext_d2i'
openssl.c:(.text+0xd16): undefined reference to `sk_num'
openssl.c:(.text+0xd36): undefined reference to `sk_value'
openssl.c:(.text+0xd60): undefined reference to `GENERAL_NAMES_free'
openssl.c:(.text+0xe39): undefined reference to `GENERAL_NAMES_free'
openssl.c:(.text+0xe52): undefined reference to `X509_get_subject_name'
openssl.c:(.text+0xe7d): undefined reference to `X509_NAME_get_index_by_NID'
openssl.c:(.text+0xe8f): undefined reference to `X509_NAME_get_entry'
openssl.c:(.text+0xe97): undefined reference to `X509_NAME_ENTRY_get_data'
openssl.c:(.text+0xea7): undefined reference to `ASN1_STRING_type'
openssl.c:(.text+0xebd): undefined reference to `ASN1_STRING_to_UTF8'
openssl.c:(.text+0xf5f): undefined reference to `CRYPTO_free'
openssl.c:(.text+0xf71): undefined reference to `ASN1_STRING_data'
openssl.c:(.text+0xf7f): undefined reference to `ASN1_STRING_length'
openssl.c:(.text+0x1004): undefined reference to `GENERAL_NAMES_free'
openssl.c:(.text+0x1044): undefined reference to `ASN1_STRING_length'
openssl.c:(.text+0x1064): undefined reference to `CRYPTO_malloc'
openssl.c:(.text+0x107d): undefined reference to `ASN1_STRING_data'
./lib/libcurl.a(libcurl_la-openssl.o): In function `ossl_connect_step3':
openssl.c:(.text+0x110e): undefined reference to `SSL_get1_session'
openssl.c:(.text+0x1195): undefined reference to `BIO_s_mem'
openssl.c:(.text+0x119d): undefined reference to `BIO_new'
openssl.c:(.text+0x11c2): undefined reference to `SSL_get_peer_certificate'
openssl.c:(.text+0x1209): undefined reference to `X509_get_subject_name'
openssl.c:(.text+0x1256): undefined reference to `ASN1_TIME_print'
openssl.c:(.text+0x126a): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x129b): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x12b9): undefined reference to `ASN1_TIME_print'
openssl.c:(.text+0x12cd): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x12fe): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x1308): undefined reference to `BIO_free'
openssl.c:(.text+0x1341): undefined reference to `X509_get_issuer_name'
openssl.c:(.text+0x13ae): undefined reference to `i2d_X509_PUBKEY'
openssl.c:(.text+0x13cb): undefined reference to `CRYPTO_malloc'
openssl.c:(.text+0x13f4): undefined reference to `i2d_X509_PUBKEY'
openssl.c:(.text+0x1409): undefined reference to `CRYPTO_free'
openssl.c:(.text+0x147a): undefined reference to `SSL_get_peer_cert_chain'
openssl.c:(.text+0x1490): undefined reference to `sk_num'
openssl.c:(.text+0x14ad): undefined reference to `BIO_s_mem'
openssl.c:(.text+0x14b5): undefined reference to `BIO_new'
openssl.c:(.text+0x14f5): undefined reference to `sk_value'
openssl.c:(.text+0x1502): undefined reference to `X509_get_subject_name'
openssl.c:(.text+0x1514): undefined reference to `X509_NAME_print_ex'
openssl.c:(.text+0x1528): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x1559): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x1563): undefined reference to `X509_get_issuer_name'
openssl.c:(.text+0x1575): undefined reference to `X509_NAME_print_ex'
openssl.c:(.text+0x1589): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x15ba): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x15ca): undefined reference to `ASN1_INTEGER_get'
openssl.c:(.text+0x15de): undefined reference to `BIO_printf'
openssl.c:(.text+0x15f2): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x1623): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x162d): undefined reference to `X509_get_serialNumber'
openssl.c:(.text+0x1661): undefined reference to `BIO_printf'
openssl.c:(.text+0x1681): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x16b2): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x16c9): undefined reference to `i2a_ASN1_OBJECT'
openssl.c:(.text+0x16dd): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x170e): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x1725): undefined reference to `ASN1_TIME_print'
openssl.c:(.text+0x1739): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x176a): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x1782): undefined reference to `ASN1_TIME_print'
openssl.c:(.text+0x1796): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x17c7): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x17d9): undefined reference to `i2a_ASN1_OBJECT'
openssl.c:(.text+0x17ed): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x181e): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x1828): undefined reference to `X509_get_pubkey'
openssl.c:(.text+0x185a): undefined reference to `EVP_PKEY_free'
openssl.c:(.text+0x186b): undefined reference to `sk_num'
openssl.c:(.text+0x1885): undefined reference to `sk_num'
openssl.c:(.text+0x189d): undefined reference to `sk_value'
openssl.c:(.text+0x18a5): undefined reference to `BIO_s_mem'
openssl.c:(.text+0x18ad): undefined reference to `BIO_new'
openssl.c:(.text+0x18c1): undefined reference to `X509_EXTENSION_get_object'
openssl.c:(.text+0x18d2): undefined reference to `i2t_ASN1_OBJECT'
openssl.c:(.text+0x18e1): undefined reference to `X509V3_EXT_print'
openssl.c:(.text+0x1905): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x1997): undefined reference to `BIO_free'
openssl.c:(.text+0x19c7): undefined reference to `X509_free'
openssl.c:(.text+0x19ee): undefined reference to `X509_free'
openssl.c:(.text+0x1a4b): undefined reference to `X509_EXTENSION_get_data'
openssl.c:(.text+0x1a56): undefined reference to `ASN1_STRING_print'
openssl.c:(.text+0x1a87): undefined reference to `BIO_printf'
openssl.c:(.text+0x1aaf): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x1ae0): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x1aed): undefined reference to `PEM_write_bio_X509'
openssl.c:(.text+0x1b01): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x1b32): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x1b4d): undefined reference to `BIO_free'
openssl.c:(.text+0x1b5a): undefined reference to `SSL_SESSION_free'
openssl.c:(.text+0x1bb2): undefined reference to `PEM_read_X509'
openssl.c:(.text+0x1bd7): undefined reference to `X509_check_issued'
openssl.c:(.text+0x1bf8): undefined reference to `X509_free'
openssl.c:(.text+0x1c05): undefined reference to `X509_free'
openssl.c:(.text+0x1d16): undefined reference to `X509_free'
openssl.c:(.text+0x1e4d): undefined reference to `BIO_puts'
openssl.c:(.text+0x1e5f): undefined reference to `BN_num_bits'
openssl.c:(.text+0x1e72): undefined reference to `BIO_printf'
openssl.c:(.text+0x1e86): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x1eb7): undefined reference to `BIO_ctrl'
openssl.c:(.text+0x205d): undefined reference to `X509_free'
openssl.c:(.text+0x206b): undefined reference to `SSL_get_verify_result'
openssl.c:(.text+0x20a3): undefined reference to `X509_verify_cert_error_string'
openssl.c:(.text+0x2109): undefined reference to `CRYPTO_free'
openssl.c:(.text+0x211f): undefined reference to `X509_free'
openssl.c:(.text+0x21a1): undefined reference to `X509_free'
openssl.c:(.text+0x21a8): undefined reference to `X509_free'
openssl.c:(.text+0x21d1): undefined reference to `X509_free'
openssl.c:(.text+0x2229): undefined reference to `X509_verify_cert_error_string'
./lib/libcurl.a(libcurl_la-openssl.o): In function `ossl_connect_common':
openssl.c:(.text+0x2450): undefined reference to `SSLv23_client_method'
openssl.c:(.text+0x2461): undefined reference to `SSL_CTX_free'
openssl.c:(.text+0x2469): undefined reference to `SSL_CTX_new'
openssl.c:(.text+0x24f2): undefined reference to `SSL_CTX_ctrl'
openssl.c:(.text+0x2576): undefined reference to `SSL_CTX_set_default_passwd_cb_userdata'
openssl.c:(.text+0x2587): undefined reference to `SSL_CTX_set_default_passwd_cb'
openssl.c:(.text+0x2677): undefined reference to `SSLv2_client_method'
openssl.c:(.text+0x2690): undefined reference to `SSL_CTX_set_msg_callback'
openssl.c:(.text+0x26a3): undefined reference to `SSL_CTX_ctrl'
openssl.c:(.text+0x26ad): undefined reference to `SSLv3_client_method'
openssl.c:(.text+0x2760): undefined reference to `d2i_PKCS12_fp'
openssl.c:(.text+0x277e): undefined reference to `PKCS12_PBE_add'
openssl.c:(.text+0x27ac): undefined reference to `PKCS12_parse'
openssl.c:(.text+0x27b9): undefined reference to `ERR_get_error'
openssl.c:(.text+0x27c3): undefined reference to `ERR_error_string'
openssl.c:(.text+0x27e6): undefined reference to `PKCS12_free'
openssl.c:(.text+0x2812): undefined reference to `SSL_CTX_set_cipher_list'
openssl.c:(.text+0x284c): undefined reference to `SSL_CTX_use_certificate_file'
openssl.c:(.text+0x2856): undefined reference to `ERR_get_error'
openssl.c:(.text+0x2865): undefined reference to `ERR_error_string'
openssl.c:(.text+0x2885): undefined reference to `ERR_peek_error'
openssl.c:(.text+0x2894): undefined reference to `ERR_error_string'
openssl.c:(.text+0x2930): undefined reference to `SSL_CTX_load_verify_locations'
openssl.c:(.text+0x2992): undefined reference to `SSL_CTX_use_certificate_chain_file'
openssl.c:(.text+0x29a0): undefined reference to `ERR_get_error'
openssl.c:(.text+0x29af): undefined reference to `ERR_error_string'
openssl.c:(.text+0x29f4): undefined reference to `SSL_new'
openssl.c:(.text+0x2a0c): undefined reference to `SSL_get_certificate'
openssl.c:(.text+0x2a21): undefined reference to `X509_get_pubkey'
openssl.c:(.text+0x2a2e): undefined reference to `SSL_get_privatekey'
openssl.c:(.text+0x2a39): undefined reference to `EVP_PKEY_copy_parameters'
openssl.c:(.text+0x2a41): undefined reference to `EVP_PKEY_free'
openssl.c:(.text+0x2a4b): undefined reference to `SSL_free'
openssl.c:(.text+0x2a55): undefined reference to `SSL_CTX_check_private_key'
openssl.c:(.text+0x2aa7): undefined reference to `SSL_CTX_use_PrivateKey_file'
openssl.c:(.text+0x2b31): undefined reference to `ENGINE_ctrl'
openssl.c:(.text+0x2bbd): undefined reference to `X509_LOOKUP_file'
openssl.c:(.text+0x2bc9): undefined reference to `SSL_CTX_get_cert_store'
openssl.c:(.text+0x2bd4): undefined reference to `X509_STORE_add_lookup'
openssl.c:(.text+0x2bf2): undefined reference to `X509_load_crl_file'
openssl.c:(.text+0x2c5f): undefined reference to `ENGINE_ctrl_cmd'
openssl.c:(.text+0x2c7e): undefined reference to `SSL_CTX_use_certificate'
openssl.c:(.text+0x2ca8): undefined reference to `X509_free'
openssl.c:(.text+0x2cd9): undefined reference to `X509_free'
openssl.c:(.text+0x2d00): undefined reference to `ERR_get_error'
openssl.c:(.text+0x2d0f): undefined reference to `ERR_error_string'
openssl.c:(.text+0x2d63): undefined reference to `SSL_CTX_get_cert_store'
openssl.c:(.text+0x2d70): undefined reference to `X509_STORE_set_flags'
openssl.c:(.text+0x2db2): undefined reference to `SSL_CTX_set_verify'
openssl.c:(.text+0x2dee): undefined reference to `SSL_free'
openssl.c:(.text+0x2df7): undefined reference to `SSL_new'
openssl.c:(.text+0x2e0c): undefined reference to `SSL_set_connect_state'
openssl.c:(.text+0x2e3f): undefined reference to `SSL_set_session'
openssl.c:(.text+0x2e4c): undefined reference to `ERR_get_error'
openssl.c:(.text+0x2e5b): undefined reference to `ERR_error_string'
openssl.c:(.text+0x2e95): undefined reference to `UI_create_method'
openssl.c:(.text+0x2ea6): undefined reference to `UI_OpenSSL'
openssl.c:(.text+0x2eae): undefined reference to `UI_method_get_opener'
openssl.c:(.text+0x2eb9): undefined reference to `UI_method_set_opener'
openssl.c:(.text+0x2ebe): undefined reference to `UI_OpenSSL'
openssl.c:(.text+0x2ec6): undefined reference to `UI_method_get_closer'
openssl.c:(.text+0x2ed1): undefined reference to `UI_method_set_closer'
openssl.c:(.text+0x2ee0): undefined reference to `UI_method_set_reader'
openssl.c:(.text+0x2eef): undefined reference to `UI_method_set_writer'
openssl.c:(.text+0x2f0f): undefined reference to `ENGINE_load_private_key'
openssl.c:(.text+0x2f1c): undefined reference to `UI_destroy_method'
openssl.c:(.text+0x2f37): undefined reference to `SSL_CTX_use_PrivateKey'
openssl.c:(.text+0x2f62): undefined reference to `EVP_PKEY_free'
openssl.c:(.text+0x2f71): undefined reference to `PKCS12_free'
openssl.c:(.text+0x2f83): undefined reference to `SSL_CTX_use_certificate'
openssl.c:(.text+0x2f8d): undefined reference to `ERR_get_error'
openssl.c:(.text+0x2f97): undefined reference to `ERR_error_string'
openssl.c:(.text+0x2fbf): undefined reference to `EVP_PKEY_free'
openssl.c:(.text+0x2fcc): undefined reference to `X509_free'
openssl.c:(.text+0x2fd3): undefined reference to `X509_free'
openssl.c:(.text+0x2fe0): undefined reference to `sk_pop_free'
openssl.c:(.text+0x3019): undefined reference to `SSL_CTX_use_PrivateKey'
openssl.c:(.text+0x3049): undefined reference to `EVP_PKEY_free'
openssl.c:(.text+0x30af): undefined reference to `SSL_CTX_check_private_key'
openssl.c:(.text+0x30cd): undefined reference to `sk_num'
openssl.c:(.text+0x30ea): undefined reference to `sk_num'
openssl.c:(.text+0x3101): undefined reference to `sk_pop'
openssl.c:(.text+0x3118): undefined reference to `SSL_CTX_ctrl'
openssl.c:(.text+0x312e): undefined reference to `SSL_CTX_add_client_CA'
openssl.c:(.text+0x31c9): undefined reference to `SSL_set_fd'
openssl.c:(.text+0x31fb): undefined reference to `ERR_get_error'
openssl.c:(.text+0x320a): undefined reference to `ERR_error_string'
openssl.c:(.text+0x3267): undefined reference to `EVP_PKEY_free'
openssl.c:(.text+0x3274): undefined reference to `X509_free'
openssl.c:(.text+0x327b): undefined reference to `X509_free'
openssl.c:(.text+0x3288): undefined reference to `sk_pop_free'
./lib/libcurl.a(libcurl_la-openssl.o): In function `ossl_send':
openssl.c:(.text+0x331b): undefined reference to `ERR_clear_error'
openssl.c:(.text+0x333a): undefined reference to `SSL_write'
openssl.c:(.text+0x338a): undefined reference to `SSL_get_error'
openssl.c:(.text+0x33ea): undefined reference to `ERR_get_error'
openssl.c:(.text+0x33f5): undefined reference to `ERR_error_string'
./lib/libcurl.a(libcurl_la-openssl.o): In function `ossl_recv':
openssl.c:(.text+0x3466): undefined reference to `ERR_clear_error'
openssl.c:(.text+0x348b): undefined reference to `SSL_read'
openssl.c:(.text+0x34db): undefined reference to `SSL_get_error'
openssl.c:(.text+0x3501): undefined reference to `ERR_get_error'
openssl.c:(.text+0x3520): undefined reference to `ERR_error_string'
./lib/libcurl.a(libcurl_la-openssl.o): In function `Curl_ossl_close_all':
openssl.c:(.text+0x3571): undefined reference to `ENGINE_finish'
openssl.c:(.text+0x357d): undefined reference to `ENGINE_free'
./lib/libcurl.a(libcurl_la-openssl.o): In function `Curl_ossl_close':
openssl.c:(.text+0x35aa): undefined reference to `SSL_shutdown'
openssl.c:(.text+0x35b3): undefined reference to `SSL_set_connect_state'
openssl.c:(.text+0x35bc): undefined reference to `SSL_free'
openssl.c:(.text+0x35d2): undefined reference to `SSL_CTX_free'
./lib/libcurl.a(libcurl_la-openssl.o): In function `Curl_ossl_shutdown':
openssl.c:(.text+0x365c): undefined reference to `ERR_clear_error'
openssl.c:(.text+0x3675): undefined reference to `SSL_read'
openssl.c:(.text+0x3685): undefined reference to `SSL_get_error'
openssl.c:(.text+0x36a7): undefined reference to `ERR_get_error'
openssl.c:(.text+0x36bd): undefined reference to `ERR_error_string'
openssl.c:(.text+0x36ea): undefined reference to `SSL_free'
openssl.c:(.text+0x3755): undefined reference to `SSL_get_shutdown'
openssl.c:(.text+0x380b): undefined reference to `SSL_shutdown'
./lib/libcurl.a(libcurl_la-openssl.o): In function `Curl_ossl_engines_list':
openssl.c:(.text+0x3835): undefined reference to `ENGINE_get_first'
openssl.c:(.text+0x384f): undefined reference to `ENGINE_get_next'
openssl.c:(.text+0x385f): undefined reference to `ENGINE_get_id'
./lib/libcurl.a(libcurl_la-openssl.o): In function `Curl_ossl_set_engine_default':
openssl.c:(.text+0x38a8): undefined reference to `ENGINE_set_default'
openssl.c:(.text+0x38b8): undefined reference to `ENGINE_get_id'
openssl.c:(.text+0x38df): undefined reference to `ENGINE_get_id'
./lib/libcurl.a(libcurl_la-openssl.o): In function `Curl_ossl_set_engine':
openssl.c:(.text+0x3912): undefined reference to `ENGINE_get_first'
openssl.c:(.text+0x3927): undefined reference to `ENGINE_get_next'
openssl.c:(.text+0x393b): undefined reference to `ENGINE_get_id'
openssl.c:(.text+0x395c): undefined reference to `ENGINE_finish'
openssl.c:(.text+0x3969): undefined reference to `ENGINE_free'
openssl.c:(.text+0x397d): undefined reference to `ENGINE_init'
openssl.c:(.text+0x3989): undefined reference to `ENGINE_free'
openssl.c:(.text+0x398e): undefined reference to `ERR_get_error'
./lib/libcurl.a(libcurl_la-openssl.o): In function `Curl_ossl_check_cxn':
openssl.c:(.text+0x3a16): undefined reference to `SSL_peek'
./lib/libcurl.a(libcurl_la-openssl.o): In function `Curl_ossl_cleanup':
openssl.c:(.text+0x3a45): undefined reference to `EVP_cleanup'
openssl.c:(.text+0x3a4a): undefined reference to `ENGINE_cleanup'
openssl.c:(.text+0x3a4f): undefined reference to `CRYPTO_cleanup_all_ex_data'
openssl.c:(.text+0x3a54): undefined reference to `ERR_free_strings'
./lib/libcurl.a(libcurl_la-openssl.o): In function `Curl_ossl_init':
openssl.c:(.text+0x3a75): undefined reference to `ENGINE_load_builtin_engines'
openssl.c:(.text+0x3a83): undefined reference to `CONF_modules_load_file'
openssl.c:(.text+0x3a88): undefined reference to `SSL_load_error_strings'
openssl.c:(.text+0x3a8d): undefined reference to `SSL_library_init'
openssl.c:(.text+0x3a98): undefined reference to `OPENSSL_add_all_algorithms_noconf'
./lib/libcurl.a(libcurl_la-openssl.o): In function `Curl_ossl_session_free':
openssl.c:(.text+0xb01): undefined reference to `SSL_SESSION_free'
./lib/libcurl.a(libcurl_la-openssl.o): In function `Curl_ossl_cleanup':
openssl.c:(.text+0x3a5f): undefined reference to `ERR_remove_state'
./lib/libcurl.a(libcurl_la-md5.o): In function `Curl_md5it':
md5.c:(.text+0xfd): undefined reference to `MD5_Init'
md5.c:(.text+0x11a): undefined reference to `MD5_Update'
md5.c:(.text+0x125): undefined reference to `MD5_Final'
./lib/libcurl.a(libcurl_la-md5.o):(.data.rel.ro+0x0): undefined reference to `MD5_Init'
./lib/libcurl.a(libcurl_la-md5.o):(.data.rel.ro+0x8): undefined reference to `MD5_Update'
./lib/libcurl.a(libcurl_la-md5.o):(.data.rel.ro+0x10): undefined reference to `MD5_Final'
./lib/libcurl.a(libcurl_la-md5.o):(.data.rel.ro+0x40): undefined reference to `MD5_Init'
./lib/libcurl.a(libcurl_la-md5.o):(.data.rel.ro+0x48): undefined reference to `MD5_Update'
./lib/libcurl.a(libcurl_la-md5.o):(.data.rel.ro+0x50): undefined reference to `MD5_Final'
./lib/libcurl.a(libcurl_la-curl_ntlm_core.o): In function `Curl_ntlm_core_mk_nt_hash':
curl_ntlm_core.c:(.text+0x3a0): undefined reference to `MD4_Init'
curl_ntlm_core.c:(.text+0x3ae): undefined reference to `MD4_Update'
curl_ntlm_core.c:(.text+0x3b9): undefined reference to `MD4_Final'
./lib/libcurl.a(libcurl_la-curl_ntlm_core.o): In function `setup_des_key':
curl_ntlm_core.c:(.text+0x494): undefined reference to `DES_set_odd_parity'
curl_ntlm_core.c:(.text+0x49f): undefined reference to `DES_set_key'
./lib/libcurl.a(libcurl_la-curl_ntlm_core.o): In function `Curl_ntlm_core_mk_lm_hash':
curl_ntlm_core.c:(.text+0x536): undefined reference to `DES_ecb_encrypt'
curl_ntlm_core.c:(.text+0x55b): undefined reference to `DES_ecb_encrypt'
./lib/libcurl.a(libcurl_la-curl_ntlm_core.o): In function `Curl_ntlm_core_lm_resp':
curl_ntlm_core.c:(.text+0x5fb): undefined reference to `DES_ecb_encrypt'
curl_ntlm_core.c:(.text+0x620): undefined reference to `DES_ecb_encrypt'
curl_ntlm_core.c:(.text+0x63f): undefined reference to `DES_ecb_encrypt'
collect2: ld returned 1 exit status
make: *** [bin/smapvss] Error 1


<think>嗯,用户的问题是关于在Windows上使用VisualStudio进行C++开发,通过Linux远程编程实现QQ邮箱的SMTP协议邮件自动发送和接收管理。需要参考之前提供的两个引用信息。先整理用户的核心需求点:1)跨平台开发(Win+Linux)2)QQ邮箱的SMTP集成3)自动化管理流程。从引用内容看,特别需要注意MIME格式构建和"\r\n.\r\n"结束符这样的细节,这些在代码实现时容易出错。考虑到用户明确要求QQ邮箱,提醒用户需要开启SMTP服务并获取授权码而非密码非常重要。引用[2]提到的邮件头与实际服务器地址不验证的特性也值得注意——在实现抄送/密送功能时需要特别注意这个坑。接下来要考虑具体实现路径。Linux远程编程意味着核心逻辑应该部署在Linux环境,那推荐VS的RemoteDevelopment扩展是最合适的。邮件功能模块可以拆分成三块:认证会话(核心SMTP指令)、MIME构建(包括邮件头和正文编码)、自动化触发机制(定时任务或事件驱动)。特别要注意引用的那个数据结束符标志,遗忘会导致邮件卡在发送队列。用户还提到接收邮件,其实引用里没有明确说明POP3/IMAP的部分。准备在回答时补充POP3的简要流程图,因为QQ邮箱同时支持两种协议,而自动化管理通常用POP3收取更简单。但考虑用户问题中写的是“了解如何利用SMTP协议”,所以接收部分不会展开太多代码示例。</think> 以下是在Windows的Visual Studio中实现C++跨平台开发,通过SMTP协议自动化管理QQ邮件的完整解决方案: --- ### 一、开发环境配置(Windows→Linux) 1. **VS远程开发环境** - 安装扩展:`Remote Development` (VS扩展商店) - 配置步骤: ```bash # 在Linux服务器安装依赖 sudo apt install openssh-server build-essential gdb ``` ```cpp // VS中:连接Linux → 配置CMake工具链 → 同步代码 ``` 2. **跨平台库选择** - 网络库:`libcurl` (跨平台SMTP支持) - XML解析:`pugixml` (处理邮件配置) - 安装命令: ```bash sudo apt install libcurl4-openssl-dev libpugixml-dev ``` --- ### 二、QQ邮箱SMTP发送实现(核心代码) ```cpp #include <curl/curl.h> #include <string> void sendQQmail(const std::string& to, const std::string& subject) { CURL* curl = curl_easy_init(); if (curl) { // 配置SMTP参数 curl_easy_setopt(curl, CURLOPT_URL, "smtps://smtp.qq.com:465"); curl_easy_setopt(curl, CURLOPT_USERNAME, "your_email@qq.com"); curl_easy_setopt(curl, CURLOPT_PASSWORD, "授权码"); // 需开启SMTP服务 // 构建MIME邮件体(参考引用[1][2]) std::string mime = "From: <your_email@qq.com>\r\n" "To: <" + to + ">\r\n" "Subject: " + subject + "\r\n" "MIME-Version: 1.0\r\n" "Content-Type: text/plain; charset=utf-8\r\n\r\n" "这是自动化测试邮件\r\n"; curl_easy_setopt(curl, CURLOPT_READFUNCTION, [](char* buffer, size_t size, size_t nitems, void* data) -> size_t { static bool sent = false; if(!sent) { memcpy(buffer, static_cast<std::string*>(data)->c_str(), size*nitems); sent = true; return size*nitems; } return 0; // 结束标记 }); curl_easy_setopt(curl, CURLOPT_READDATA, &mime); // 关键结束符(引用[2]) curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); CURLcode res = curl_easy_perform(curl); if(res != CURLE_OK) fprintf(stderr, "邮件发送失败: %s\n", curl_easy_strerror(res)); curl_easy_cleanup(curl); } } ``` --- ### 三、邮件接收实现(POP3协议) ```cpp #include <curl/curl.h> std::string receiveQQmail() { CURL* curl = curl_easy_init(); std::string response; if (curl) { curl_easy_setopt(curl, CURLOPT_URL, "pop3s://pop.qq.com:995"); curl_easy_setopt(curl, CURLOPT_USERNAME, "your_email@qq.com"); curl_easy_setopt(curl, CURLOPT_PASSWORD, "授权码"); // 设置数据接收回调 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, [](char* ptr, size_t size, size_t nmemb, std::string* data) -> size_t { data->append(ptr, size*nmemb); return size*nmemb; }); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response); curl_easy_perform(curl); curl_easy_cleanup(curl); } return response; // 解析邮件内容需处理MIME格式 } ``` --- ### 四、自动化管理方案 1. **关键配置步骤** - 开启QQ邮箱SMTP/POP3服务: > 邮箱设置 → 账户 → POP3/SMTP服务 → 生成授权码 - 加密存储授权码:使用`libsodium`库加密配置文件 2. **定时任务实现** ```cpp // Linux定时器 (结合cron) #include <unistd.h> while(true) { checkNewEmails(); // 邮件接收检测 sendDailyReport(); // 自动发送日报 sleep(86400); // 24小时周期 } ``` 3. **错误处理机制** - SMTP响应码检查(例如:221/250为成功) - 网络重连策略:指数退避算法重试 --- ### 五、调试技巧 1. **抓包验证** ```bash tcpdump -i eth0 port 465 -w smtp.pcap # 抓取SSL流量需解密密钥 ``` 2. **日志记录** ```cpp curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); // 打印协议交互详情 ``` --- ### 注意事项: 1. 使用465/995端口(QQ邮箱强制SSL) 2. 授权码非登录密码(重要安全措施) 3. 邮件内容长度限制:QQ邮箱单封邮件最大50MB[^1]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值