我想編譯一個簡單的ssl程序(它來自openssl書籍源代碼)。 該程序有以下文件:common.h common.c client.c server.c如何使用OpenSSL編譯一個簡單的程序?
我已經安裝了openssl 0.9.7,所以我與本書有相同的版本。 我已經下載了源碼和./configure,make,make test,make install在home目錄下。
在COMMON.H有以下包括:
#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/rand.h>
#include <openssl/ssl.h>
#include <openssl/x509v3.h>
我跑的gcc -Wall common.c中client.c -o客戶,但我得到了以下錯誤:
common.c: In function ‘init_OpenSSL’:
common.c:12:5: warning: implicit declaration of function ‘THREAD_setup’
/tmp/ccvI3HX4.o: In function `handle_error':
common.c:(.text+0x3a): undefined reference to `ERR_print_errors_fp'
/tmp/ccvI3HX4.o: In function `init_OpenSSL':
common.c:(.text+0x51): undefined reference to `THREAD_setup'
common.c:(.text+0x5a): undefined reference to `SSL_library_init'
common.c:(.text+0x97): undefined reference to `SSL_load_error_strings'
/tmp/ccRA0Co9.o: In function `do_client_loop':
client.c:(.text+0x71): undefined reference to `BIO_write'
/tmp/ccRA0Co9.o: In function `main':
client.c:(.text+0xbb): undefined reference to `BIO_new_connect'
client.c:(.text+0x106): undefined reference to `BIO_ctrl'
client.c:(.text+0x18e): undefined reference to `BIO_free'
collect2: ld returned 1 exit status
顯然它不能鏈接到頭文件... 當我運行如在一個論壇建議gcc -Wall common.c client.c -o客戶端-lcrypto -lssl我得到
common.c: In function ‘init_OpenSSL’:
common.c:12:5: warning: implicit declaration of function ‘THREAD_setup’
/tmp/cc2gjx8W.o: In function `init_OpenSSL':
common.c:(.text+0x51): undefined reference to `THREAD_setup'
collect2: ld returned 1 exit status
但添加-lpthread不會幫助解決問題...
任何想法,爲什麼出現這種情況,如何解決呢?
我的猜測是,lcrypto和lssl默認情況下,在Ubuntu和做-lcypto告訴鏈接器看系統頭,且不使用OpenSSL的安裝者安裝...
任何幫助或指針是不勝感激!
謝謝!
當你說'標題'時,你的意思是'庫'嗎? – 2011-06-10 09:08:32
是的抱歉,我的意思是庫 – 2011-06-10 09:11:01
如果您擔心鏈接到哪個庫,請使用-L選項指定顯式路徑。 – Nick 2011-06-10 10:08:44