QT 5.5.1。所以与Android库 [英] QT 5.5.1 .so library with android

查看:209
本文介绍了QT 5.5.1。所以与Android库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经下载了armeabi和x86的android平台的OpenSSL编译库从这里< /一>,并试图将其加载在.pro文件:

  INCLUDEPATH + = C:\ TEMP \ OpenSSL的\ OpenSSL的换Android- prebuilt \ OpenSSL的-1.0.2 \包括\
LIBS + = -LC:\ TEMP \ OpenSSL的\ OpenSSL的换Android- prebuilt \ OpenSSL的-1.0.2 \ armeabi-V7A \ lib目录\
-llibssl
-llibcrypto
 

我也试图与 -llibssl.so -llibcrypto.so -llibssl.a -llibcrypto.a 但这个错误occures:

  

collect2.exe:-1:错误:错误:LD返回1退出状态

在code是SHA1的简单的使用,它是在MSVC 12.0运行具有的.lib库成功:

mainwindow.cpp

 的#includemainwindow.h
#包括ui_mainwindow.h
#包括QMessageBox提示
#包括&LT;的OpenSSL / sha.h&GT;

主窗口::主窗口(QWidget的*父):
    QMainWindow中(父),
    用户界面(UI新::主窗口)
{
    用户界面 - &GT; setupUi(本);
    const的无符号字符IBUF [] =计算SHA1;
    为const char ibuf1 [] =计算SHA1;
    unsigned char型OBUF [20];

    SHA1(IBUF,strlen的(ibuf1),OBUF);

    INT I;
    对于(I = 0; I&小于20;我++){
        的printf(%02X,OBUF [I]);
    }
    的printf(\ N);
}

主窗口::〜主窗口()
{
    删除用户界面;
}

无效的MainWindow :: on_pushButton_clicked()
{
    QMessageBox提示::有关(这一点,TR(测试),TR(Hellow人!!!));
}
 

当然,我已阅读论坛所以这里是完整的日志:

<$p$p><$c$c>C:\Users\niki\Downloads\android-ndk-r10e/toolchains/arm-linux-androideabi-4.9/$p$pbuilt/windows/bin/arm-linux-androideabi-g++ --sysroot = C:\ Users \用户尼基\下载\的Andr​​oid NDK-r10e /平台/ Android的9 /弓臂/轮候册,-soname,libtestAndroid.so轮候册, - 没有不确定轮候册, - Z,noexecstack -shared -o libtestAndroid.so main.obj mainwindow.obj moc_mainwindow.obj-LC:\ Users \用户尼基\下载\的Andr​​oid NDK-r10e /来源/ CXX-STL / GNU-的libstdc ++ / 4.9 /库/ armeabi -LC:\ Users \用户尼基\下载\的Andr​​oid NDK-r10e /平台/ Android的9 /弓臂// usr / lib目录-LC:/Qt/5.5/android_armv5/lib -lQt5Widgets -Lc:\ utils的\机器人\ NDK /来源/ CXX-STL / GNU-的libstdc ++ / 4.8 /库/ armeabi -Lc:\ utils的\机器人\ NDK /平台/ Android的9 /弓臂// usr / lib目录-lQt5Gui -lQt5Core -lGLESv2 -lgnustl_shared -llog -lz -lm -ldl -lc -lgcc mainwindow.obj:mainwindow.cpp:功能主窗口::主窗口(QWidget的*):错误:未定义的引用SHA1 collect2.exe:错误:LD返回1退出状态 生成文件:83:配方目标的libtestAndroid.so'失败 的mingw32-MAK​​E:*** [libtestAndroid.so]错误1 十点47分05秒:在处理C:\ Qt的\工具\ mingw492_32 \ BIN \的mingw32-make.exe退出,code 2。 错误同时建立/部署项目testAndroid(试剂盒:安卓的armeabi(GCC 4.9,Qt的5.5.1)) 当执行步骤做

似乎SHA1就是问题所在。在sha.h它被定义

 的#ifdef __cplusplus
为externC{
#ENDIF
的#ifdef __cplusplus
}
#ENDIF
 

因此​​这不是问题。有一些Android.mk文件。该怎么办?我应该在.pro文件中以某种方式加载它?我只是想尝试的OpenSSL在机器人的使用之前编译它是舒尔就可以工作(因为compilling需要时间,而且必须在Linux上完成)。

解决方案

我的问题是noobie。当你要链接共享库LIB开始时似乎应该错过它,在我的情况下,这个工作:

  INCLUDEPATH + = C:\ TEMP \ OpenSSL的\ OpenSSL的换Android- prebuilt \ OpenSSL的-1.0.2 \包括\
LIBS + = -LC:\ TEMP \ OpenSSL的\ OpenSSL的换Android- prebuilt \ OpenSSL的-1.0.2 \ armeabi-V7A \ lib中-lssl
LIBS + = -LC:\ TEMP \ OpenSSL的\ OpenSSL的换Android- prebuilt \ OpenSSL的-1.0.2 \ armeabi-V7A \ lib中-lcrypto
 

的通知我已经分居 libcrypto.so和libssl.so libcrypto.a和libssl.a 两目录 - lib和LIB1。对我来说,只有静态库(.a)中的工作,共享库给我的错误。

I have downloaded openssl compiled library for armeabi and x86 android platforms from here and tried to load it in the .pro file:

INCLUDEPATH += C:\Temp\openssl\OpenSSL-for-Android-Prebuilt\openssl-1.0.2\include\
LIBS += -LC:\Temp\openssl\OpenSSL-for-Android-Prebuilt\openssl-1.0.2\armeabi-v7a\lib \
-llibssl
-llibcrypto

I have also tried with -llibssl.so -llibcrypto.so and -llibssl.a -llibcrypto.a but this error occures:

collect2.exe:-1: error: error: ld returned 1 exit status

The code is simple usage of SHA1 and it is running on MSVC 12.0 with .lib libraries successfully:

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QMessageBox"
#include <openssl/sha.h>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    const unsigned char ibuf[] = "compute sha1";
    const char ibuf1[] = "compute sha1";
    unsigned char obuf[20];

    SHA1(ibuf, strlen(ibuf1), obuf);

    int i;
    for (i = 0; i < 20; i++) {
        printf("%02x ", obuf[i]);
    }
    printf("\n");
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    QMessageBox::about(this,tr("Test"),tr("Hellow man!!!"));
}

Of course I have read forums so here is the full log:

C:\Users\niki\Downloads\android-ndk-r10e/toolchains/arm-linux-androideabi-4.9/prebuilt/windows/bin/arm-linux-androideabi-g++ --sysroot=C:\Users\niki\Downloads\android-ndk-r10e/platforms/android-9/arch-arm/ -Wl,-soname,libtestAndroid.so -Wl,--no-undefined -Wl,-z,noexecstack -shared -o libtestAndroid.so main.obj mainwindow.obj moc_mainwindow.obj   -LC:\Users\niki\Downloads\android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi -LC:\Users\niki\Downloads\android-ndk-r10e/platforms/android-9/arch-arm//usr/lib -LC:/Qt/5.5/android_armv5/lib -lQt5Widgets -Lc:\utils\android\ndk/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi -Lc:\utils\android\ndk/platforms/android-9/arch-arm//usr/lib -lQt5Gui -lQt5Core -lGLESv2 -lgnustl_shared -llog -lz -lm -ldl -lc -lgcc
mainwindow.obj:mainwindow.cpp:function MainWindow::MainWindow(QWidget*): error: undefined reference to 'SHA1'
collect2.exe: error: ld returned 1 exit status
makefile:83: recipe for target 'libtestAndroid.so' failed
mingw32-make: *** [libtestAndroid.so] Error 1
10:47:05: The process "C:\Qt\Tools\mingw492_32\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project testAndroid (kit: Android for armeabi (GCC 4.9, Qt 5.5.1))
When executing step "Make"

It seems that SHA1 is the problem. In sha.h it is defined

#ifdef  __cplusplus
extern "C" {
#endif
#ifdef  __cplusplus
}
#endif

so this is not the issue. There is some Android.mk file. What to do? Should I load it somehow in .pro file? I just wanted to try usage of openssl in android before compile it to be shure it is possible to work(because compilling will take time and must be done on linux).

解决方案

My question was noobie. Seems when you want to link shared libraries begining with "lib" you should miss it so in my case this worked:

INCLUDEPATH += C:\Temp\openssl\OpenSSL-for-Android-Prebuilt\openssl-1.0.2\include\
LIBS += -LC:\Temp\openssl\OpenSSL-for-Android-Prebuilt\openssl-1.0.2\armeabi-v7a\lib -lssl
LIBS += -LC:\Temp\openssl\OpenSSL-for-Android-Prebuilt\openssl-1.0.2\armeabi-v7a\lib -lcrypto

Notice I have separated libcrypto.so and libssl.so from libcrypto.a and libssl.a in two directories - lib and lib1. For me only static libs(.a) worked, shared libs give me error.

这篇关于QT 5.5.1。所以与Android库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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