未定义的参考链接到库

时间:2017-07-11 18:04:03

标签: c++ compiler-errors

我正在尝试编译g ++代码。在我的main.cpp中,我得到了依赖项列表:

#include <string.h>
#include <stdlib.h>

#include "mbedtls/platform.h"
#include "mbedtls/net.h"
#include "mbedtls/debug.h"
#include "mbedtls/ssl.h"
#include "mbedtls/entropy.h"
#include "mbedtls/ctr_drbg.h"
#include "mbedtls/error.h"
#include "mbedtls/certs.h"

#include "nghttp2/nghttp2.h"
#include <math.h>

特别是,nghttp2mbedtls是我安装的开源github库。见下面的照片

enter image description here

现在,我运行了以下命令g++ -Wall -L/usr/local/lib/ main.cpp Http2Client.cpp -o main,但不幸的是,它给了我以下错误。他们基本上说他们对库函数有未定义的引用:

enter image description here

我错过了什么吗?

更新

pi@raspberrypi:~/Downloads $ g++ -Wall -L/usr/local/lib/  main.cpp Http2Client.cpp -o main 
Http2Client.cpp: In function ‘void mbedtls_debug(void*, int, const char*, int, const char*)’:
Http2Client.cpp:73:17: warning: unused variable ‘MBTAG’ [-Wunused-variable]
     const char *MBTAG = "mbedtls";
                 ^
Http2Client.cpp:74:11: warning: unused variable ‘file_sep’ [-Wunused-variable]
     char *file_sep;
           ^
Http2Client.cpp: In constructor ‘Http2Client::Http2Client()’:
Http2Client.cpp:132:56: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
     ESP_LOGI(TAG, "Seeding the random number generator");
                                                        ^
Http2Client.cpp: In member function ‘bool Http2Client::begin(std::string, std::string, int)’:
Http2Client.cpp:158:52: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
  ESP_LOGI(TAG, "Loading the CA root certificate...");
                                                    ^
Http2Client.cpp:164:66: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
   ESP_LOGE(TAG, "mbedtls_x509_crt_parse returned -0x%x\n\n", -ret);
                                                                  ^
Http2Client.cpp:168:53: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
  ESP_LOGI(TAG, "Setting hostname for TLS session...");
                                                     ^
Http2Client.cpp:172:64: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
   ESP_LOGE(TAG, "mbedtls_ssl_set_hostname returned -0x%x", -ret);
                                                                ^
Http2Client.cpp:176:53: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
  ESP_LOGI(TAG, "Setting up the SSL/TLS structure...");
                                                     ^
Http2Client.cpp:182:63: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
   ESP_LOGE(TAG, "mbedtls_ssl_config_defaults returned %d", ret);
                                                               ^
Http2Client.cpp:203:61: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
   ESP_LOGE(TAG, "mbedtls_ssl_setup returned -0x%x\n\n", -ret);
                                                             ^
Http2Client.cpp: In member function ‘void Http2Client::performIo(Connection*)’:
Http2Client.cpp:228:36: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
  ESP_LOGI(TAG, "performIo finished");
                                    ^
Http2Client.cpp:242:62: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
     ESP_LOGI(TAG, "***nghttp2_session_send failed:%d", result);
                                                              ^
Http2Client.cpp:247:50: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
    ESP_LOGI(TAG, "nghttp2_session_want_read: not");
                                                  ^
Http2Client.cpp:255:65: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
    ESP_LOGI(TAG, "***nghttp2_session_mem_recv failed:%d", result);
                                                                 ^
Http2Client.cpp:259:36: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
  ESP_LOGI(TAG, "performIo finished");
                                    ^
Http2Client.cpp: In member function ‘bool Http2Client::connectToServer()’:
Http2Client.cpp:299:56: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘const char*’ [-Wformat=]
     printf("Connecting to $s:%d...", host.c_str(), port);
                                                        ^
Http2Client.cpp:299:56: warning: too many arguments for format [-Wformat-extra-args]
Http2Client.cpp:306:63: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
         ESP_LOGE(TAG, "mbedtls_net_connect returned -%x", -ret);
                                                               ^
Http2Client.cpp:312:40: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
      ESP_LOGI(TAG, "mbedtls Connected.");
                                        ^
Http2Client.cpp:317:56: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
     ESP_LOGI(TAG, "Performing the SSL/TLS handshake...");
                                                        ^
Http2Client.cpp:323:71: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
             ESP_LOGE(TAG, "mbedtls_ssl_handshake returned -0x%x", -ret);
                                                                       ^
Http2Client.cpp:329:47: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
          ESP_LOGI(TAG, "SSL/TLS is handshaked");
                                               ^
Http2Client.cpp:333:56: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
     ESP_LOGI(TAG, "Verifying peer X.509 certificate...");
                                                        ^
Http2Client.cpp:340:59: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
         ESP_LOGW(TAG, "Failed to verify peer certificate!");
                                                           ^
Http2Client.cpp:343:51: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
         ESP_LOGW(TAG, "verification info: %s", buf);
                                                   ^
Http2Client.cpp:346:52: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
         ESP_LOGI(TAG, "X.509 Certificate verified.");
                                                    ^
Http2Client.cpp: In function ‘ssize_t send_callback(nghttp2_session*, const uint8_t*, size_t, int, void*)’:
Http2Client.cpp:360:40: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
  ESP_LOGI(TAG, "nghttp2 event step6...");
                                        ^
Http2Client.cpp:367:40: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
  ESP_LOGI(TAG, "nghttp2 event step7...");
                                        ^
Http2Client.cpp:372:40: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
  ESP_LOGI(TAG, "nghttp2 event step8...");
                                        ^
Http2Client.cpp:375:41: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
   ESP_LOGI(TAG, "nghttp2 event step9...");
                                         ^
Http2Client.cpp:378:43: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
    ESP_LOGI(TAG, "nghttp2 event step10...");
                                           ^
Http2Client.cpp:380:57: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
    ESP_LOGE(TAG, "mbedtls_ssl_write returned -0x%d", -rv);
                                                         ^
Http2Client.cpp: In function ‘ssize_t recv_callback(nghttp2_session*, uint8_t*, size_t, int, void*)’:
Http2Client.cpp:407:56: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
  ESP_LOGI(TAG, "got data, data length:%d data:", length);
                                                        ^
Http2Client.cpp:412:55: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
   ESP_LOGE(TAG, "mbedtls_ssl_read returned -0x%x", -rv);
                                                       ^
Http2Client.cpp:414:36: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
   ESP_LOGI(TAG, "connection closed");
                                    ^
Http2Client.cpp:417:60: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
   ESP_LOGI(TAG, "mbedtls_ssl_read successed, return:%d", rv);
                                                            ^
Http2Client.cpp: In function ‘int on_frame_send_callback(nghttp2_session*, const nghttp2_frame*, void*)’:
Http2Client.cpp:424:40: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
  ESP_LOGI(TAG, "nghttp2 event step4...");
                                        ^
Http2Client.cpp: In function ‘int on_frame_recv_callback(nghttp2_session*, const nghttp2_frame*, void*)’:
Http2Client.cpp:453:50: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
  ESP_LOGI(TAG, "on_frame_recv_callback step%d", 1);
                                                  ^
Http2Client.cpp:481:52: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
   ESP_LOGI(TAG, "get frame type:%d", frame->hd.type)
                                                    ^
Http2Client.cpp: In function ‘int on_stream_close_callback(nghttp2_session*, int32_t, uint32_t, void*)’:
Http2Client.cpp:497:42: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
  ESP_LOGI(TAG, "on_stream_close_callback");
                                          ^
Http2Client.cpp:506:60: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
    ESP_LOGE(TAG, "nghttp2_session_terminate_session:%d", rv);
                                                            ^
Http2Client.cpp: In function ‘int on_data_chunk_recv_callback(nghttp2_session*, uint8_t, int32_t, const uint8_t*, size_t, void*)’:
Http2Client.cpp:521:45: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
  ESP_LOGI(TAG, "on_data_chunk_recv_callback");
                                             ^
Http2Client.cpp: In member function ‘void Http2Client::submitRequest(Connection*, Request*)’:
Http2Client.cpp:570:56: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
    ESP_LOGE(TAG, "nghttp2_submit_request:%d", stream_id);
                                                        ^
Http2Client.cpp: In member function ‘bool Http2Client::initNghttp2()’:
Http2Client.cpp:586:2: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
  };
  ^
Http2Client.cpp:586:2: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
Http2Client.cpp:593:63: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
   ESP_LOGE(TAG, "nghttp2_session_callbacks_new failed: %d", rv);
                                                               ^
Http2Client.cpp:604:56: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
   ESP_LOGE(TAG, "nghttp2_submit_settings failed:%d", rv);
                                                        ^
Http2Client.cpp: At global scope:
Http2Client.cpp:69:13: warning: ‘void mbedtls_debug(void*, int, const char*, int, const char*)’ defined but not used [-Wunused-function]
 static void mbedtls_debug(void *ctx, int level,
             ^
/tmp/ccNAWLWE.o: In function `Http2Client::Http2Client()':
Http2Client.cpp:(.text+0x144): undefined reference to `mbedtls_ssl_init'
Http2Client.cpp:(.text+0x158): undefined reference to `mbedtls_x509_crt_init'
Http2Client.cpp:(.text+0x168): undefined reference to `mbedtls_ctr_drbg_init'
Http2Client.cpp:(.text+0x18c): undefined reference to `mbedtls_ssl_config_init'
Http2Client.cpp:(.text+0x19c): undefined reference to `mbedtls_entropy_init'
/tmp/ccNAWLWE.o: In function `Http2Client::begin(std::string, std::string, int)':
Http2Client.cpp:(.text+0x2b8): undefined reference to `mbedtls_ctr_drbg_seed'
Http2Client.cpp:(.text+0x31c): undefined reference to `mbedtls_x509_crt_parse'
Http2Client.cpp:(.text+0x38c): undefined reference to `mbedtls_ssl_set_hostname'
Http2Client.cpp:(.text+0x408): undefined reference to `mbedtls_ssl_config_defaults'
Http2Client.cpp:(.text+0x454): undefined reference to `mbedtls_ssl_session_reset'
Http2Client.cpp:(.text+0x464): undefined reference to `mbedtls_net_free'
Http2Client.cpp:(.text+0x480): undefined reference to `mbedtls_ssl_conf_authmode'
Http2Client.cpp:(.text+0x4a4): undefined reference to `mbedtls_ssl_conf_ca_chain'
Http2Client.cpp:(.text+0x4c4): undefined reference to `mbedtls_ssl_conf_rng'
Http2Client.cpp:(.text+0x4e0): undefined reference to `mbedtls_ssl_setup'
Http2Client.cpp:(.text+0x5a0): undefined reference to `mbedtls_entropy_func'
Http2Client.cpp:(.text+0x5ac): undefined reference to `_binary_server_root_cert_pem_end'
Http2Client.cpp:(.text+0x5b0): undefined reference to `_binary_server_root_cert_pem_start'
Http2Client.cpp:(.text+0x5c8): undefined reference to `mbedtls_ctr_drbg_random'
/tmp/ccNAWLWE.o: In function `Http2Client::performIo(Connection*)':
Http2Client.cpp:(.text+0x60c): undefined reference to `nghttp2_session_want_write'
Http2Client.cpp:(.text+0x638): undefined reference to `nghttp2_session_send'
Http2Client.cpp:(.text+0x674): undefined reference to `nghttp2_session_want_read'
Http2Client.cpp:(.text+0x6cc): undefined reference to `mbedtls_ssl_read'
Http2Client.cpp:(.text+0x6f8): undefined reference to `nghttp2_session_mem_recv'
/tmp/ccNAWLWE.o: In function `Http2Client::end()':
Http2Client.cpp:(.text+0x790): undefined reference to `nghttp2_session_del'
Http2Client.cpp:(.text+0x7a0): undefined reference to `mbedtls_ssl_close_notify'
Http2Client.cpp:(.text+0x7b0): undefined reference to `mbedtls_ssl_session_reset'
Http2Client.cpp:(.text+0x7c0): undefined reference to `mbedtls_net_free'
/tmp/ccNAWLWE.o: In function `Http2Client::connectToServer()':
Http2Client.cpp:(.text+0x8c4): undefined reference to `mbedtls_net_init'
Http2Client.cpp:(.text+0x958): undefined reference to `mbedtls_net_connect'
Http2Client.cpp:(.text+0x9ac): undefined reference to `mbedtls_ssl_session_reset'
Http2Client.cpp:(.text+0x9bc): undefined reference to `mbedtls_net_free'
Http2Client.cpp:(.text+0xa04): undefined reference to `mbedtls_ssl_set_bio'
Http2Client.cpp:(.text+0xa68): undefined reference to `mbedtls_ssl_session_reset'
Http2Client.cpp:(.text+0xa78): undefined reference to `mbedtls_net_free'
Http2Client.cpp:(.text+0xaa4): undefined reference to `mbedtls_ssl_handshake'
Http2Client.cpp:(.text+0xaec): undefined reference to `mbedtls_ssl_get_verify_result'
Http2Client.cpp:(.text+0xb4c): undefined reference to `mbedtls_x509_crt_verify_info'
Http2Client.cpp:(.text+0xba8): undefined reference to `mbedtls_net_send'
Http2Client.cpp:(.text+0xbac): undefined reference to `mbedtls_net_recv'
/tmp/ccNAWLWE.o: In function `send_callback(nghttp2_session*, unsigned char const*, unsigned int, int, void*)':
Http2Client.cpp:(.text+0xc40): undefined reference to `mbedtls_ssl_write'
/tmp/ccNAWLWE.o: In function `recv_callback(nghttp2_session*, unsigned char*, unsigned int, int, void*)':
Http2Client.cpp:(.text+0xd3c): undefined reference to `mbedtls_ssl_get_bytes_avail'
Http2Client.cpp:(.text+0xd68): undefined reference to `mbedtls_ssl_read'
/tmp/ccNAWLWE.o: In function `on_frame_send_callback(nghttp2_session*, nghttp2_frame const*, void*)':
Http2Client.cpp:(.text+0xe88): undefined reference to `nghttp2_session_get_stream_user_data'
/tmp/ccNAWLWE.o: In function `on_frame_recv_callback(nghttp2_session*, nghttp2_frame const*, void*)':
Http2Client.cpp:(.text+0x1074): undefined reference to `nghttp2_session_get_stream_user_data'
/tmp/ccNAWLWE.o: In function `on_stream_close_callback(nghttp2_session*, int, unsigned int, void*)':
Http2Client.cpp:(.text+0x122c): undefined reference to `nghttp2_session_get_stream_user_data'
Http2Client.cpp:(.text+0x124c): undefined reference to `nghttp2_session_terminate_session'
/tmp/ccNAWLWE.o: In function `on_data_chunk_recv_callback(nghttp2_session*, unsigned char, int, unsigned char const*, unsigned int, void*)':
Http2Client.cpp:(.text+0x12d4): undefined reference to `nghttp2_session_get_stream_user_data'
/tmp/ccNAWLWE.o: In function `Http2Client::setupNghttp2Callbacks(nghttp2_session_callbacks*)':
Http2Client.cpp:(.text+0x1354): undefined reference to `nghttp2_session_callbacks_set_send_callback'
Http2Client.cpp:(.text+0x1360): undefined reference to `nghttp2_session_callbacks_set_recv_callback'
Http2Client.cpp:(.text+0x136c): undefined reference to `nghttp2_session_callbacks_set_on_frame_send_callback'
Http2Client.cpp:(.text+0x1378): undefined reference to `nghttp2_session_callbacks_set_on_frame_recv_callback'
Http2Client.cpp:(.text+0x1384): undefined reference to `nghttp2_session_callbacks_set_on_stream_close_callback'
Http2Client.cpp:(.text+0x1390): undefined reference to `nghttp2_session_callbacks_set_on_data_chunk_recv_callback'
/tmp/ccNAWLWE.o: In function `Http2Client::submitRequest(Connection*, Request*)':
Http2Client.cpp:(.text+0x14f4): undefined reference to `nghttp2_submit_request'
/tmp/ccNAWLWE.o: In function `Http2Client::initNghttp2()':
Http2Client.cpp:(.text+0x1608): undefined reference to `nghttp2_session_callbacks_new'
Http2Client.cpp:(.text+0x1674): undefined reference to `nghttp2_session_client_new'
Http2Client.cpp:(.text+0x1688): undefined reference to `nghttp2_session_callbacks_del'
Http2Client.cpp:(.text+0x16a4): undefined reference to `nghttp2_submit_settings'
collect2: error: ld returned 1 exit status

0 个答案:

没有答案