我正在尝试从SSL客户端程序调用方法SSL_export_keying_material()。但是,调用此方法会导致程序编译失败。我收到以下错误。我怎样才能解决这个编译错误?
clang -cc1 version 5.1 based upon LLVM 3.4svn default target x86_64-apple-darwin13.2.0
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.1/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.9.0 -o withssl -lssl -lcrypto /var/folders/1b/smlgh1256t95yw11pqs2hz380000gn/T/withssl-08785c.o -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.1/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"_SSL_export_keying_material", referenced from:
_main in withssl-08785c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1
谢谢
答案 0 :(得分:4)
如何解决此编译错误?
您需要安装最新版本的OpenSSL。默认情况下,Apple提供版本0.9.8,但它不提供SSL_export_keying_material
:
$ nm /usr/lib/libssl.dylib | grep SSL_export_keying_material
$
这是我的1.0.1i副本:
$ nm /usr/local/ssl/macosx-x64/lib/libssl.a | grep SSL_export_keying_material
...
0000000000002810 T _SSL_export_keying_material
00000000000068c8 S _SSL_export_keying_material.eh
以下是在/usr/local/ssl
中获取和安装OpenSSL 1.0.1i的方法。还有其他config
选项可供选择。有关详细信息,请参阅OpenSSL wiki上的Compilation and Installation。
wget https://www.openssl.org/source/openssl-1.0.1i.tar.gz
tar xzf openssl-1.0.1i.tar.gz
cd openssl-1.0.1i
export KERNEL_BITS=64
./config enable-ec_nistp_64_gcc_128 --openssldir=/usr/local/ssl
make
sudo make install
之后,请务必编译并链接/usr/local/ssl
中的OpenSSL设备。
此外,Apple链接器忽略LD_PRELOAD
,-Bstatic
和-Wl,--rpath
。 确定 使用DYLD_LIBRARY_PATH
(OS X等效于LD_PRELOAD
)。否则,您将针对1.0.1(来自/usr/local/ssl
)编译,但在运行时链接到0.9.8(来自/usr/lib
)。有关Apple的运行时链接编辑器的一些信息,请参阅dyld(1)
。
如果针对1.0.1进行编译但针对0.9.8进行运行时链接,那么您将遇到无法解释的崩溃。原因不是很明显,但是因为0.9.8和1.0.1 不二进制兼容。
我经常把它扔进我的代码中以防止它:
long version = SSLeay();
ASSERT(version == OPENSSL_VERSION_NUMBER);
if (version != OPENSSL_VERSION_NUMBER)
{
/* Handle incorrect version at runtime */
}
上面的代码检查编译时版本是否与运行时版本相同。