【问题标题】:Building patched 64 bit OpenSSL on OSX and Ubuntu在 OSX 和 Ubuntu 上构建修补的 64 位 OpenSSL
【发布时间】:2012-12-19 08:27:48
【问题描述】:

我正在尝试设置 OpenSSL 的 patched version 以使用 DTLS,但遇到了很多麻烦。我假设这是由于我对 gcc 和链接 c 库缺乏了解。特别是,我不断看到人们说要链接到 lib/ 子文件夹,但我找不到 OpenSSL 的链接。我也是question on building 32 bit 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

构建(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

现在我将尝试编译a simple piece of code that uses the patched 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

建筑:

./config
make

检查库(忽略日期,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 上,此命令给我与之前相同的错误,即找不到 _BIO_dgram_get_peer

【问题讨论】:

  • 嗨,nflacco。我的 mac 10.6 也有同样的问题。你知道“(隐藏的)警告”是关于什么的吗?或者它会影响什么?
  • 不知道警告是关于什么的!

标签: c linux macos gcc openssl


【解决方案1】:

您必须将库放在命令行的最后:

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

本网站上有许多重复的问题,解释了原因和方法。 ld 的文档解释得很好,是终极参考。

【讨论】:

  • 在 Ubuntu 上,这让我成功了——我还需要 -ldl
猜你喜欢
  • 2016-12-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-18
  • 2018-04-16
  • 1970-01-01
  • 2014-05-15
  • 2011-03-10
相关资源
最近更新 更多