2015-05-09 15 views
2

我試圖用openssl-references編譯一個c程序。我正在使用Linux Mint 17.1,並安裝了開發包「libssl-dev」。鏈接OpenSSL時沒有引用BIO函數

#include <openssl/bio.h> 
#include <openssl/err.h> 
#include &lt;openssl/ssl.h> 
... 

void send_smtp_request(BIO *bio, const char *req) 
{ 
    BIO_puts(bio, req); 
    BIO_flush(bio); 
    printf("%s", req);  
} 

如果我編譯代碼:

gcc -o client bio-ssl-smtpcli2.c 

我得到這個錯誤:

/tmp/ccCHrti2.o: In function 'send_smtp_request': 
bio-ssl-smtpcli2.c:(.text+0x1f): undefined reference to 'BIO_puts' 
bio-ssl-smtpcli2.c:(.text+0x3a): undefined reference to 'BIO_ctrl' 

有人有一個想法如何解決這一問題?

+1

[現有C項目中OpenSSL庫的鏈接問題]的可能副本(http://stackoverflow.com/questions/5700617/linking-problem-of-openssl-library-in-existing-c-project),[在GCC中鏈接OpenSSL libcrypto](http://stackoverflow.com/q/18835219),[引用一堆尚未解決的OpenSSL符號的錯誤清楚地存在?](http://stackoverflow.com/q/15318978), ... – jww

回答

2

我設法用編譯你的函數:

gcc main.c -o main -I /usr/local/ssl/include -L /usr/local/ssl/lib -lssl -lcrypto -Wall 

更多解釋相關:

  • -I /usr/local/ssl/include增加/usr/local/ssl/include到包含搜索路徑。

  • -L /usr/local/ssl/lib/usr/local/ssl/lib添加到庫搜索路徑中。

  • -lssl -lcrypto鏈接庫libcrypto和的libssl

  • -lcrypto必須遵循-lssl監守LD是單通連接

  • Wall使所有的警告。

我的猜測是你缺少-lcrypto

+0

謝謝,這幫助了很多 – S1J0

+0

我收到了一個新錯誤:/usr/local/ssl/lib//libssl.a(ssl_lib.o):在函數'SSL_clear'中:ssl_lib.c :(.text + 0x19e):未定義的引用'COMP_CTX_free' – S1J0

+0

我發現[對同一問題的這個答案](http://ubuntuforums.org/archive/index.php/t-985136.html):嘗試將'-lssl'放入'-lcrypto'的前面。我相應地改變了我的答案。 – francis

相關問題