2012-06-12 131 views
5

我已經使用openssl庫在C代碼中包含以下頭文件。Openssl編譯錯誤

#include <sys/types.h> 
#include <sys/socket.h> 
#include <netinet/in.h> 
#include <arpa/inet.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <unistd.h> 
#include <errno.h> 
#include <string.h> 
#include <time.h> 
#ifdef __VMS 
#include <in.h> 
#include <inet.h> 
#else 
#include <netinet/in.h> 
#include <arpa/inet.h> 
#endif 
#include <openssl/crypto.h> 
#include <openssl/ssl.h> 
#include <openssl/err.h> 

然後我編譯使用gcc -o openssl -lssl -lcrypt openssl.c 在我的辦公室,這個代碼編譯和運行正常,但在我的家裏系統(兩者都是在辦公室和Ubuntu 12.04在家裏的linux的debian 6)程序,它提供了以下錯誤:

/tmp/ccZcmLk4.o: In function `main': 
server.c:(.text+0x3d): undefined reference to `SSL_library_init' 
server.c:(.text+0x42): undefined reference to `SSL_load_error_strings' 
server.c:(.text+0x47): undefined reference to `SSLv3_method' 
server.c:(.text+0x57): undefined reference to `SSL_CTX_new' 
server.c:(.text+0x6f): undefined reference to `ERR_print_errors_fp' 
server.c:(.text+0x97): undefined reference to `SSL_CTX_use_certificate_file' 
server.c:(.text+0xa8): undefined reference to `ERR_print_errors_fp' 
server.c:(.text+0xd0): undefined reference to `SSL_CTX_use_PrivateKey_file' 
server.c:(.text+0xe1): undefined reference to `ERR_print_errors_fp' 
server.c:(.text+0xf9): undefined reference to `SSL_CTX_check_private_key' 
server.c:(.text+0x154): undefined reference to `SSL_CTX_load_verify_locations' 
server.c:(.text+0x165): undefined reference to `ERR_print_errors_fp' 
server.c:(.text+0x18d): undefined reference to `SSL_CTX_set_verify' 
server.c:(.text+0x1a1): undefined reference to `SSL_CTX_set_verify_depth' 
server.c:(.text+0x397): undefined reference to `SSL_new' 
server.c:(.text+0x3c2): undefined reference to `SSL_set_fd' 
server.c:(.text+0x3ce): undefined reference to `SSL_accept' 
server.c:(.text+0x3e6): undefined reference to `ERR_print_errors_fp' 
server.c:(.text+0x3fe): undefined reference to `SSL_get_current_cipher' 
server.c:(.text+0x406): undefined reference to `SSL_CIPHER_get_name' 
server.c:(.text+0x42e): undefined reference to `SSL_get_peer_certificate' 
server.c:(.text+0x455): undefined reference to `X509_get_subject_name' 
server.c:(.text+0x46d): undefined reference to `X509_NAME_oneline' 
server.c:(.text+0x4b1): undefined reference to `X509_get_issuer_name' 
server.c:(.text+0x4c9): undefined reference to `X509_NAME_oneline' 
server.c:(.text+0x50d): undefined reference to `X509_free' 
server.c:(.text+0x593): undefined reference to `SSL_write' 
server.c:(.text+0x5ab): undefined reference to `ERR_print_errors_fp' 
server.c:(.text+0x5d3): undefined reference to `SSL_read' 
server.c:(.text+0x5eb): undefined reference to `ERR_print_errors_fp' 
collect2: ld returned 1 exit status 

據我所知,這是由於我的家用電腦沒有某些庫。但任何人都可以告訴我,我需要爲此安裝哪些庫?提前致謝。

回答

17

把庫源文件後:

​​3210

參見:http://www.network-theory.co.uk/docs/gccintro/gccintro_18.html

+0

嗯,這工作。但是它回覆了我沒有上任的警告。 'server.c:在函數'main'中: server.c:55:7:warning:賦值丟棄來自指針目標類型的'const'限定符[默認情況下啓用]' 恐怕我必須粘貼整個代碼告訴你問題在哪裏。但它當然不在辦公室。 –

+0

@Hari你正在使用不同的編譯器版本,是嗎?在編譯期間調整標誌以協調警告或適應不同的編譯器輸出。最好你應該在兩個位置使用相同的編譯器版本。 – HonkyTonk

+3

我必須執行'-lssl -lcrypto'(注意'o'!)來避免對符號PEM_read_bio_DHparams引用一個神祕的未定義引用 –