问题描述
我自己从源代码构建了libcrypto.a
和libssl.a
,并为OpenSSL
的配置脚本指定了darwin64-x86_64-cc
(对于64位)和darwin-i386-cc
(对于32位).
用lipo
创建胖库,并将它们作为依赖项添加到我的Xcode
项目中.
I have build libcrypto.a
and libssl.a
myself from source, specifying darwin64-x86_64-cc
(for 64-bit) and darwin-i386-cc
(for 32-bit) to OpenSSL
's configure script.
Created the fat libraries with lipo
and added them as a dependency in my Xcode
project.
但是,我遇到了未定义的符号错误:
However, I'am getting an undefined symbol error:
undefined symbols for architecture x86_64:
"_OPENSSL_ia32cap_P", referenced from:
_AES_cbc_encrypt in libcrypto.a(aes-x86_64.o)
ld: symbol(s) not found for architecture x86_64
注意:不过,使用相同的技术在iOS上效果很好.
Note: Using the same technique works fine for iOS, though.
lipo -detailed_info libcrypto.a
显示:
Fat header in: libcrypto.a
fat_magic 0xcafebabe
nfat_arch 2
architecture i386
cputype CPU_TYPE_I386
cpusubtype CPU_SUBTYPE_I386_ALL
offset 48
size 2700624
align 2^2 (4)
architecture x86_64
cputype CPU_TYPE_X86_64
cpusubtype CPU_SUBTYPE_X86_64_ALL
offset 2700672
size 3938432
align 2^2 (4)
推荐答案
在静态库的情况下,这似乎是x64的代码生成器中的错误.
It looks to be a bug in the code generator for x64 in the static library case.
最简单的非补丁openssl更改解决方法是在代码中的某个位置添加对OPENSSL_cleanse
的引用,即使未使用它也是如此.这样可以修正链接时间参考.
The easiest, non patch openssl change workaround is to add a reference to OPENSSL_cleanse
somewhere in your code, even if it's not used. That will fix up the link-time reference.
实际上是在某些汇编代码中引用了该符号.
What's actually happening is that the symbol is being referenced in some assembly code.
汇编代码只是说_OPENSSL_ia32cap_P
是一个外部符号,而没有使交叉链接表明需要链接它.这对libcrypto.dylib
有用,因为在生成.dylib
时引用已解析.文件;但是,在.a
情况下,引用永远不会解析,因为实际上包含符号的唯一代码是x86_64cpuid.o
,只有在使用该.o
提供的任何例程时,该链接才会被链接.
The assembly code simply says that _OPENSSL_ia32cap_P
is an extern symbol, without making the cross-link to state that it needs to be linked in. This works for libcrypto.dylib
because the reference is resolved when generating the .dylib
file; however the reference is never resolved in the .a
case because the only code that actually contains the symbol is x86_64cpuid.o
, which only gets linked in if you use any of the routines provided by that .o
.
此文件中的符号包含OPENSSL_cleanse
,因此,如果您引用此例程,则该链接有效.
Symbols in this file includes OPENSSL_cleanse
, so if you reference this routine, the link works.
这篇关于带有Fat库的OS X上体系结构x86_64的未定义符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!