QT + OpenSSL +安卓 [英] QT + OpenSSL + Android

查看:392
本文介绍了QT + OpenSSL +安卓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置OpenSSL库.为我的Qt项目.在Linux下,它可以与内置的OpenSSL一起正常工作.我将此添加到了我的.pro文件中:

I would like to setup the OpenSSL lib. for my Qt project. Under Linux it is working fine with the built-in OpenSSL. I added this to my .pro file:

LIBS+=-lcrypto
PKGCONFIG += openssl

但是,如果我在Android中使用它,则会出现错误.我遵循了以下指示:

But if I use it in Android, it gives error. I followed this instructions:

$ . ./setenv-android.sh
$ cd openssl-1.0.1h/
$ perl -pi -e 's/install: all install_docs install_sw/install: install_docs install_sw/g' Makefile.org
$ ./config shared -no-ssl2 -no-ssl3 -no-comp -no-hw -no-engine --openssldir=/usr/local/ssl/$ANDROID_API
$ make depend
$ ./Configure shared android-armv7
$ make build_libs
$ export CC=/home/laci/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
$ export AR=/home/laci/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar
$ export ANDROID_DEV=/home/laci/android-ndk-r10/platforms/android-14/arch-arm/usr/
$ make all
$ sudo -E make install CC=$ANDROID_TOOLCHAIN/arm-linux-androideabi-gcc RANLIB=$ANDROID_TOOLCHAIN/arm-linux-androideabi-ranlib

这些网站是我的来源:

  • OpenSSL wiki
  • QtDoc - Adding OpenSSL support

我在做什么错了?

预先感谢您的回答

推荐答案

LIBS + =-lcrypto

LIBS+=-lcrypto

我在这里看到两个潜在的问题.首先,您可能需要LIBS += -lssl -lcrypto.

I see two potential problems here. First, you probably need LIBS += -lssl -lcrypto.

第二,QT可能使用主机的OpenSSL(即/usr/lib中的i386或x86_64)而不是目标服务器的OpenSSL(即/usr/中的libssllibcrypto)本地/ssl/android/lib`).要修复它,我发现的最简单的方法是指定库的 full 路径:

Second, QT is probably using the host's OpenSSL (i.e., i386 or x86_64 in /usr/lib), and not the target's OpenSSL (i.e., libssl and libcrypto in /usr/local/ssl/android/lib`). To fix it, the easiest way I have found is to specify the full path to the library:

LIBS += /usr/local/ssl/android/lib/libssl.a /usr/local/ssl/android/lib/libcrypto.a

您必须避免仅使用-lssl -lcrypto,该链接链接到共享对象(如果有). Android附带了OpenSSL 0.9.8.因此,您将在编译时针对1.0.1h进行编译,而在运行时针对Android 0.9.8进行链接.这将导致一堆无法解释的错误.

You have to avoid using just -lssl -lcrypto, which links to a shared object if available. Android carries around OpenSSL 0.9.8. So you will compile against 1.0.1h at compile time, but link against Androids 0.9.8 at runtime. That will cause a bunch of unexplained errors.

之所以会发生这种现象,是因为Android的主进程Zygote在启动后会加载OpenSSL的0.9.8版本. Zygote分叉到您的过程之后,已经加载了0.9.8.他们的操作系统将不会加载您的1.0.1版本,因为已经满足了链接依赖性.

The behavior happens because Android's master process - Zygote - loads version 0.9.8 of OpenSSL after it starts. After Zygote forks into your process, 0.9.8 is already loaded. They operating system will not load your version of 1.0.1 because the link dependency is already satisfied.

这篇关于QT + OpenSSL +安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆