用于arm android的交叉编译

问题描述

我想为我的android设备构建c ++库,更具体地说,我想构建与我的Qt项目一起使用的taglib,我有一个使用taglib的音乐应用程序,为Windows和ubuntu构建了它,并且可以按预期工作,但是现在我想交叉编译taglib以在我的android手机上使用,我花了几个小时找到解决方案,我找到了一些有关工具链文件和手动cmake选项的文章,但是它们都不适合我, 我试图将CMAKE_SYstem_NAME设置为android并设置其他Cmake选项,如下所示:

set(CMAKE_SYstem_NAME Android)
message("this is host system ${CMAKE_SYstem_NAME} ${CMAKE_HOST_SYstem_NAME} {CMAKE_SYstem_VERSION}")
set(CMAKE_SYstem_VERSION 21)
set(CMAKE_ANDROID_ARCH_ABI armeabi-v7a)
set(CMAKE_ANDROID_NDK /home/sub/Downloads/android/android-ndk-r20)
set(CMAKE_ANDROID_STL_TYPE gnustl_static)

,当我使用 file 命令检查生成.so文件时,它将显示我的系统信息,如下所示:

libmylib.so: ELF 64-bit LSB shared object,x86-64,version 1 (SYSV),dynamically linked,BuildID[sha1]=4245460a39baea2cbd1f28c3a2fd8037b07fe995,with debug_info,not stripped

那么有人可以给我一些链接或帮助吗?

**更新

我的cmake命令如下:

cmake CMakeLists.txt -DCMAKE_SYstem_NAME=ANDROID -DCMAKE_TOOLCHAIN_FILE=/home/sub/Downloads/android-ndk-r21/build/cmake/android.toolchain.cmake

现在我使用新的ndk并使用它android.toolchain.cmake文件,但输出显示它不使用它:

-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_TOOLCHAIN_FILE


-- Build files have been written to: /home/sub/Documents/Projects/cpp/build-for-android

我的新CMakeLists.txt是:

cmake_minimum_required(VERSION 3.17)


project(addlib CXX)
# set(CMAKE_SYstem_NAME Android)
# message("this is host system ${CMAKE_SYstem_NAME} ${CMAKE_HOST_SYstem_NAME} ${CMAKE_SYstem_VERSION}")
# set(CMAKE_SYstem_VERSION 21)
# set(CMAKE_ANDROID_ARCH_ABI armeabi-v7a)
# set(CMAKE_ANDROID_NDK /home/sub/Downloads/android/android-ndk-r20)
# set(CMAKE_ANDROID_STL_TYPE gnustl_static)
set(BUILD_SHARED_LIBS true)
add_library(mylib main.cpp)
target_include_directories(mylib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
message(${CMAKE_CROSSCOMPILING})
install(TARGETS mylib DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/)

打开详细显示的make命令输出与以下内容相同:

/usr/local/bin/cmake -S/home/sub/Documents/Projects/cpp/build-for-android -B/home/sub/Documents/Projects/cpp/build-for-android --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/bin/cmake -E cmake_progress_start /home/sub/Documents/Projects/cpp/build-for-android/CMakeFiles /home/sub/Documents/Projects/cpp/build-for-android/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/sub/Documents/Projects/cpp/build-for-android'
make -f CMakeFiles/mylib.dir/build.make CMakeFiles/mylib.dir/depend
make[2]: Entering directory '/home/sub/Documents/Projects/cpp/build-for-android'
cd /home/sub/Documents/Projects/cpp/build-for-android && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /home/sub/Documents/Projects/cpp/build-for-android /home/sub/Documents/Projects/cpp/build-for-android /home/sub/Documents/Projects/cpp/build-for-android /home/sub/Documents/Projects/cpp/build-for-android /home/sub/Documents/Projects/cpp/build-for-android/CMakeFiles/mylib.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/sub/Documents/Projects/cpp/build-for-android'
make -f CMakeFiles/mylib.dir/build.make CMakeFiles/mylib.dir/build
make[2]: Entering directory '/home/sub/Documents/Projects/cpp/build-for-android'
[ 50%] Linking CXX shared library libmylib.so
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/mylib.dir/link.txt --verbose=1
/usr/bin/g++ -fPIC -g  -shared -Wl,-soname,libmylib.so -o libmylib.so CMakeFiles/mylib.dir/main.cpp.o 
make[2]: Leaving directory '/home/sub/Documents/Projects/cpp/build-for-android'
[100%] Built target mylib
make[1]: Leaving directory '/home/sub/Documents/Projects/cpp/build-for-android'
/usr/local/bin/cmake -E cmake_progress_start /home/sub/Documents/Projects/cpp/build-for-android/CMakeFiles 0

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)