QSsh之android版编译

今天看到有人在Qtcn.org给我留言问我QSsh的botan在android和ios 的arm下编译不通过,我就去测试了下,果然是(如果哪位哥们看到,我道个歉,前天发的,今天才看到)。以前只在win和linux下,果然arm有问题。我就去差了下原因是Botan不同平台,比同cpu和编译器的配置不同的。

所以我就去看了下QSsh用的botan的用法,他是把botan的配置那么多宏在botan.pri下根据平台和编译器进行很多定义的。仔细看了看那么多的宏和判断,而且加上我对botan不是十分的熟悉,就不敢妄自更改他的配置。我也就想了个偷懒的方法,去替换掉QSsh用的Botan,直接用自己官方下载的Botan替换掉QSsh里的Botan。

下面说下我的做法:

1、先去下载Botan库,下载地址:http://botan.randombit.net/download.html 注意,请下载最新稳定版的,1.10.8,开发板的1.11.9我第一步就没通过的。

2、进行botan配置,也就是执行“configure.py”输入参数进行配置,我是选择把所有算法生成统一的botan_all文件的。附上配置参数:

ARM V5的:

./configure.py --gen-amalgamation --cpu=arm/armv5 --os=linux --cc=gcc --with-tr1=none

如果你是win的话,应该是:

python configure.py --gen-amalgamation --cpu=arm/armv5 --os=linux --cc=gcc --with-tr1=none

ARMV7-A的:

./configure.py --gen-amalgamation --cpu=arm/armv7-a --os=linux --cc=gcc --with-tr1=none

Python需要是2.5+,我用的2.7,3.x的我不清楚,您可以试下。

此处参考:http://www.tiwoc.de/blog/2013/03/building-the-botan-library-for-android/

参数的意思我说下,

–gen-amalgamation : 生成聚合的botan_all文件的。

–cpu=arm/armv7-a : CPU的类型,arm/armv7-a 是我们用armv7-a的CPU,如果是X86/Atom或者mips的,你只需要制定其他的类型就行。

–os=linux : 操作系统类型,Android是基于Linux,所以这个是linux

–cc=gcc : 编译器系统,这儿是gcc,

–with-tr1=none :这个参数,好像是必须的,如果没这个参数是会有一个asm里的汇编错误,我那能力更改,就加上了。上面参考里的解释是:当用STLport或者其他替代GNU STL时,这个参数是必须的,我记得Android Ndk的STL是谷歌自己实现的,不是GNU STL。

此时你执行完命令,应该会在Botan的源码目录看到botan_all.h 和botan_all.cpp这两个文件,这两个是我们需要的。

3、配置QSsh源码,替换掉QSsh里的Botan。

1) 禁用QSsh自带的Botan,把src/libs/ssh/ssh.pro里在最后一句话:

include(../3rdparty/botan/botan.pri)

删除或者注释掉(注释是在这句话最前面加上#)。

2) 添加自己的Botan文件,这个可以有很多做法,我是直接加到工程里,编译到QSsh里。我的做法是:

 把botan_all.h和botan_cpp复制到/src/libs目录下,然后在src/libs/ssh/ssh.pro里添加上这两个文件,建议你在Qt-C操作,直接在ssh下右键,添加现有文件。如果是自己改文件,就SOURCES = 这个参数里加上../botan_all.cpp,HEADERS = 参数里加上../botan_all.h

3) 更改QSsh里引用的头文件,建议直接用QSsh操作。打开工程后,下面高级搜索(Search Results)里,搜索

#include <botan/botan.h>

,选择搜索并替换,全部替换为:

#include "../botan_all.h"

4) 选择你的项目套件为android对应的架构,开始编译吧。

5) 在编译中我遇到了botan错误的,你应该也会遇到,错误的行数在2w多行,错误的那句话是:

return std::make_pair<struct dirent*, std::string>(dir, m_cur_dir.second);

这个是使用make_pair有点问题,把中间的<struct dirent*, std::string>删除即可,注释也行,我的更改是:

std::make_pair/*<struct dirent*, std::string>*/(dir, m_cur_dir.second);

同样,同在这一个函数,还有几个此类的错误,只是不更改也没问题。

 

这样你编译应该就没问题了、、编译是通过的,只是我没有测试QSsh在android下的使用,如有问题可以在一起探讨。

对,附上我的环境:

OS:OpenSUSE 13.1

GCC:gcc4.8,

Qt For Android : 5.3

Python : 2.7

如果你是在Win下可能还有其他问题的、、、

附上,官方building.rst对编译IOS版Botan的说明:

For iOS using XCode

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

To cross compile for iOS, configure with::

 

$ ./configure.py –cpu=armv7 –cc=clang –cc-abi-flags=”-arch armv7 -arch armv7s –sysroot=$(IOS_SYSROOT)”

 

Along with any additional configuration arguments. Using “–no-autoload“

might be helpful as can substantially reduce code size.

 

Edit the makefile and change AR (around line 30) to::

 

AR = libtool -static -o

 

You may also want to edit LIB_OPT to use -Os to optimize for size.

 

Now build as normal with “make“. Confirm the binaries are compiled

for both architectures with::

 

$ xcrun -sdk iphoneos lipo -info botan

Architectures in the fat file: botan are: armv7 armv7s

 

Now sign the test application with::

 

$ codesign -fs “Your Name” botan-test

 

which should allow you to run the library self tests on a jailbroken

4 thoughts on “QSsh之android版编译”

  1. 您好,我用win7的qt for android来写一个ssh的小程序。按照你的方法,编译都成功了。但运行之后,遇到了错误。错误提示:dlopen(“/data/app/org.qtproject.example.test_android_qtcssh-1/lib/arm/libQtcSsh.so”, RTLD_LAZY) failed: dlopen failed: library “libQt5Test.so” not found。在网上找了很久,也没弄清libQt5Test.so文件。请问这是什么问题?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.