在OSX和Ubuntu上构build修补的64位OpenSSL

我正在尝试设置OpenSSL的补丁版本来使用DTLS,我遇到了很多麻烦。 我假设这是由于我不了解gcc和链接c库。 特别是,我不断看到人们说,链接到lib /子文件夹,但我找不到一个OpenSSL。 我也是一个关于构build32位OpenSSL的问题 ,但我正在尝试做64位。

OSX

获取源代码和补丁:

wget ftp://ftp.openssl.org/source/openssl-1.0.1c.tar.gz # get latest stable OpenSSL mv ~/Downloads/openssl-1.0.1c.tar.gz /usr/local/openssl-1.0.1c.tar.gz cd /usr/local/openssl-1.0.1c.tar.gz wget http://sctp.fh-muenster.de/dtls/dtls-bugs-1.0.1.patch # get the patch file 

build设(64位,OpenSSL默认为32位):

 export CFLAGS="-arch x86_64" export LDFLAGS="-arch x86_64" ./Configure darwin64-x86_64-cc # 64 bit config command make # .a files should be built, great 

太好了,我在OpenSSL根目录下有一些库:

 /usr/local/openssl-1.0.1c$ ll lib* -rw-r--r-- 1 nflacco staff 3286136 Jan 4 12:43 libcrypto.a -rw-r--r-- 1 nflacco staff 260 Jan 4 12:43 libcrypto.pc -rw-r--r-- 1 nflacco staff 570200 Jan 4 12:43 libssl.a -rw-r--r-- 1 nflacco staff 275 Jan 4 12:43 libssl.pc 

现在我将尝试编译使用修补的OpenSSL的一段简单代码 :

 ~$ gcc -L /usr/local/openssl-1.0.1c -lssl -lcrypto -I /usr/local/opt/openssl/include -o server server.c ld: warning: _OPENSSL_ia32cap_P has different visibility (hidden) in /usr/local/openssl-1.0.1c/libcrypto.a(x86_64cpuid.o) and (default) in /usr/local/openssl-1.0.1c/libcrypto.a(cryptlib.o) Undefined symbols for architecture x86_64: "_BIO_dgram_get_peer", referenced from: _generate_cookie_callback in ccfldIrE.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status make: *** [server] Error 1 

Ubuntu的

build造:

 ./config make 

检查库(无视date,Ubuntu认为它是圣诞节):

 /usr/local/openssl-1.0.1c$ ll lib* -rw-r--r-- 1 root root 3170340 Dec 25 17:45 libcrypto.a -rw-r--r-- 1 root root 264 Dec 25 17:46 libcrypto.pc -rw-r--r-- 1 root root 534092 Dec 25 17:45 libssl.a -rw-r--r-- 1 root root 279 Dec 25 17:46 libssl.pc 

而且,试图编译:

 gcc -L /usr/local/openssl-1.0.1c -lssl -lcrypto -I /usr/local/opt/openssl/include -o server server.c /tmp/cc0DgDl1.o: In function `generate_cookie_callback': server.c:(.text+0x8b): undefined reference to `RAND_bytes' server.c:(.text+0xba): undefined reference to `SSL_get_rbio' server.c:(.text+0xdc): undefined reference to `BIO_ctrl' server.c:(.text+0x112): undefined reference to `CRYPTO_malloc' /tmp/cc0DgDl1.o: In function `main': server.c:(.text+0x163): undefined reference to `SSL_library_init' server.c:(.text+0x168): undefined reference to `SSL_load_error_strings' server.c:(.text+0x16d): undefined reference to `SSL_library_init' /tmp/cc0DgDl1.o: In function `configure_server_ssl': server.c:(.text+0x2f5): undefined reference to `SSL_CTX_set_cipher_list' server.c:(.text+0x318): undefined reference to `SSL_CTX_ctrl' server.c:(.text+0x333): undefined reference to `SSL_CTX_use_certificate_file' server.c:(.text+0x35e): undefined reference to `SSL_CTX_use_PrivateKey_file' server.c:(.text+0x379): undefined reference to `SSL_CTX_check_private_key' server.c:(.text+0x3a4): undefined reference to `SSL_CTX_set_verify' server.c:(.text+0x3c7): undefined reference to `SSL_CTX_ctrl' server.c:(.text+0x3da): undefined reference to `SSL_CTX_set_cookie_generate_cb' server.c:(.text+0x3ed): undefined reference to `SSL_CTX_set_cookie_verify_cb' /tmp/cc0DgDl1.o: In function `start_server': server.c:(.text+0x40b): undefined reference to `DTLSv1_server_method' server.c:(.text+0x413): undefined reference to `SSL_CTX_new' collect2: ld returned 1 exit status 

更新:

在Ubuntu上,我通过将库移动到编译命令的末尾来进行编译,并添加了标志-ldl来编译时没有警告:

 gcc -L /usr/local/openssl-1.0.1c -I /usr/local/opt/openssl/include -o server server.c -lssl -lcrypto -ldl 

在OSX上,这个命令给我提供了与之前相同的错误,没有find_BIO_dgram_get_peer

您必须将这些库放在命令行上:

 gcc -L /usr/local/openssl-1.0.1c -I /usr/local/opt/openssl/include -o server server.c -lssl -lcrypto # ^^^^^^^^^^^^^^ 

在这个网站上有任何重复的这个问题,解释了什么和什么。 ld的文档很好地解释了它,并且是最终的参考。