如何使用Qt Creator为Android创建不依赖的单个本机共享库 [英] How to create a single native shared library with no dependency for Android using Qt Creator

查看:146
本文介绍了如何使用Qt Creator为Android创建不依赖的单个本机共享库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Qt Creator创建了一个共享库,并添加了Android SDK,Android NDK和Android Qt工具包.然后,我成功地为Android编译了我的库.我什至在Android应用程序中成功测试了它.

I have created a shared library using Qt Creator and I have added the Android SDK, Android NDK and Android Qt kit. Then I compiled my library for Android successfully. I even tested it in an Android application successfully.

由于我没有使用Qt库,所以我的库不依赖于庞大的Qt库.但是出乎意料的是,这是我的依赖项:

As I am not using the Qt libraries, my library does not depend on huge Qt libraries. But unexpectedly, here is my dependencies:

[matin@Lenovo-X1-Fedora ~]$ ndk-depends libMatinChess.so 
WARNING: Could not find library: libgnustl_shared.so
libMatinChess.so
libz.so
libstdc++.so
libm.so
liblog.so
libgnustl_shared.so
libdl.so
libc.so

当我检查libgnustl_shared.so时,它的大小超过5 MB.因此,在每个项目中,我都必须将这个巨大的库放在我的微型库旁边.

And when I checked the libgnustl_shared.so it has more than 5 MBs size. So I have to place this huge library next to my tiny library in every project.

另一个选择是将其静态链接.我之前曾问过问题关于如何静态链接依赖项,我发现可以通过在.pro文件中添加QMAKE_LFLAGS += -static来实现:

Another option is to link it statically. I previously asked the question about how is it possible to link a dependency statically and I figured out that it is possible by adding the QMAKE_LFLAGS += -static in my .pro file:

此标志可以完美工作,并消除了stdc ++对Windows编译的依赖.但是在android中,出现以下错误:

This flags works perfect and removes the dependency of stdc++ on Windows compilation. But in android I get the following errors:

error: cannot find -lgnustl_shared
error: cannot find -llog
error: cannot find -lz
error: cannot find -ldl

我搜索了android-ndk文件夹,发现其中没有liblog.alibz.alibdl.a文件,但是有一个libgnustl_static.a文件.

I searched my android-ndk folder and I realized that there is no liblog.a, libz.a and libdl.a files located in it but there is a libgnustl_static.a file.

我尝试使用LIBS += -Lpath/to/libdir -lgnustl_static添加它,但结果相同.

I tried to add it using LIBS += -Lpath/to/libdir -lgnustl_static but the result was the same.

在上一个问题中提到的CMake中有一个解决方案,该注释是在makefile中可以设置APP_STL := gnustl_static的选项.但是QMake中似乎没有类似的东西.

There is a solution in CMake that was mentioned in the previous question as a comment that there is the option to set APP_STL := gnustl_static in the makefile. But there seems to be no equivalent in QMake.

一个复杂的问题是,当我使用CONFIG += static时,它可以成功编译,但是不再共享我的库.它成为一个静态库.

And a complicated issue is that when I use CONFIG += static, it compiles successfully but my library is not shared anymore. it becomes a static library.

如何静态链接gnustl,以使我的库在没有其他依赖项的情况下工作?

How can I link gnustl statically so that my library works with no other dependencies?

我阅读了编译输出,发现以下行:

I read the compile output and found the following line:

/home/matin/Applications/android-ndk-r13b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ --sysroot =/home/matin/Applications/android-ndk-r13b/platforms/android-9/arch-arm/ -static -Wl,-没有未定义-Wl,-z,noexecstack-共享-Wl,-soname,libMatinChess.so -o libMatinChess.so matinchessdll.o bishop.o piece.o board.o king.o memory.manager. o pawn.o queen.o blackpawn.o骑士o rook.o whitepawn.o squarelist.o game.o 董事会历史 -L/home/matin/Applications/android-ndk-r13b/sources/cxx-stl/gnu-libstdc ++/4.9/libs/armeabi-v7a -L/home/matin/Applications/android-ndk-r13b/platforms/android-9/arch-arm//usr/lib -lgnustl_shared -llog -lz -lm -ldl -lc -lgcc

/home/matin/Applications/android-ndk-r13b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ --sysroot=/home/matin/Applications/android-ndk-r13b/platforms/android-9/arch-arm/ -static -Wl,--no-undefined -Wl,-z,noexecstack -shared -Wl,-soname,libMatinChess.so -o libMatinChess.so matinchessdll.o bishop.o piece.o board.o king.o memorymanager.o pawn.o queen.o blackpawn.o knight.o rook.o whitepawn.o squarelist.o game.o boardhistory.o -L/home/matin/Applications/android-ndk-r13b/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a -L/home/matin/Applications/android-ndk-r13b/platforms/android-9/arch-arm//usr/lib -lgnustl_shared -llog -lz -lm -ldl -lc -lgcc

我无法使用LIB -= -lgnustl_shared

推荐答案

通过阅读编译输出,我手动执行了以下命令并创建了1 MB大小的库.而且可以正常工作.

By reading the compile output, I executed the following command manually and created my library with 1 MB size. And it works correctly.

/home/matin/Applications/android-ndk-r13b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ --sysroot =/home/matin/Applications/android-ndk-r13b/platforms/android-9/arch-arm/ -Wl,-未定义-Wl,-z,noexecstack-共享-Wl,-soname,libMatinChess.so -o libMatinChess.so matinchessdll.o bishop.o piece.o board.o king.o memorymanager.o pawn .o queen.o blackpawn.o骑士o rook.o whitepawn.o squarelist.o game.o 董事会历史 -L/home/matin/Applications/android-ndk-r13b/sources/cxx-stl/gnu-libstdc ++/4.9/libs/armeabi-v7a -L/home/matin/Applications/android-ndk-r13b/platforms/android-9/arch-arm//usr/lib -lgnustl_static

/home/matin/Applications/android-ndk-r13b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ --sysroot=/home/matin/Applications/android-ndk-r13b/platforms/android-9/arch-arm/ -Wl,--no-undefined -Wl,-z,noexecstack -shared -Wl,-soname,libMatinChess.so -o libMatinChess.so matinchessdll.o bishop.o piece.o board.o king.o memorymanager.o pawn.o queen.o blackpawn.o knight.o rook.o whitepawn.o squarelist.o game.o boardhistory.o -L/home/matin/Applications/android-ndk-r13b/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a -L/home/matin/Applications/android-ndk-r13b/platforms/android-9/arch-arm//usr/lib -lgnustl_static

但是我仍然不知道如何在QMake中自动执行此命令

But still I don't know how to automate this command in QMake

这篇关于如何使用Qt Creator为Android创建不依赖的单个本机共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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