QT 5.5.1 .so library with android

给你一囗甜甜゛ 提交于 2019-12-02 16:54:58

问题


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).


回答1:


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.



来源:https://stackoverflow.com/questions/33953855/qt-5-5-1-so-library-with-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!