构建工具链与cmake的交叉编译为Android [英] Building a toolchain with cmake to cross-compile for android

查看:3145
本文介绍了构建工具链与cmake的交叉编译为Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

gcc (GCC) 4.8.1 
android-ndk-r9 

您好,

我的主机是的Fedora 19 ,我想创建一个工具链编译程序在Android上运行的,后来我想延长这种适用于iOS。

My host machine is Fedora 19 and I want to create a tool-chain for compiling programs to run on android, later I want to extend this for iOS.

我收到以下错误:

Check for working C compiler: /opt/ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc -- broken

我不知道为什么我收到这个错误,因为一切都已经安装。我还安装了的binutils-臂Linux的GNU 。不过,这是我第一次做这种类型的事情,所以很多我已经得到的东西混合起来。

I am not sure why I am getting this error, as everything has been installed. I have also installed binutils-arm-linux-gnu. However, this is my first time do this type of thing, so many I have got something mixed up.

我试图使用cmake来croos编译在Android设备上运行库创建工具链文件。

I am trying to create a toolchain file using cmake to croos-compile to run libraries on an android device.

我已经安装了Android的NDK-R9在以下位置的路径编译:

I have installed the android-ndk-r9 in the following location with the path to the compiler:

/opt/ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin

arm-linux-androideabi-addr2line
arm-linux-androideabi-ar
arm-linux-androideabi-as
arm-linux-androideabi-c++
arm-linux-androideabi-c++filt
arm-linux-androideabi-cpp
arm-linux-androideabi-elfedit
arm-linux-androideabi-g++
arm-linux-androideabi-gcc
arm-linux-androideabi-gcc-4.8
arm-linux-androideabi-gcc-ar
arm-linux-androideabi-gcc-nm
arm-linux-androideabi-gcc-ranlib
arm-linux-androideabi-gcov
arm-linux-androideabi-gdb
arm-linux-androideabi-gprof
arm-linux-androideabi-ld
arm-linux-androideabi-ld.bfd
arm-linux-androideabi-ld.gold
arm-linux-androideabi-ld.mcld
arm-linux-androideabi-nm
arm-linux-androideabi-objcopy
arm-linux-androideabi-objdump
arm-linux-androideabi-ranlib
arm-linux-androideabi-readelf
arm-linux-androideabi-run
arm-linux-androideabi-size
arm-linux-androideabi-strings
arm-linux-androideabi-strip

我的交叉编译的文件是:

My cross-compile file is:

include(CMakeForceCompiler)

set(toolchain_path /opt/ndk/toolchains)

# Target system
set(CMAKE_SYSTEM_NAME Linux)

set(CMAKE_SYSTEM_PROCESSOR arm)

set(CMAKE_SYSTEM_VERSION 1)

# Compiler to build for the target
set(CMAKE_C_COMPILER /opt/ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc)

set(CMAKE_FIND_ROOT_PATH /opt/ndk/toolchains)

我在根目录下我的工具链是运行这个从我构建/调试目录。

I run this from my build/debug directory with my toolchain being in the root directory.

[ant@localhost debug]$ cmake -DCMAKE_TOOLCHAIN_FILE=arm-eabi-gcc.cmake ../..

输出

-- The C compiler identification is GNU 4.8.0
-- Check for working C compiler: /opt/ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
-- Check for working C compiler: /opt/ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc -- broken
CMake Error at /usr/share/cmake/Modules/CMakeTestCCompiler.cmake:61 (message):
  The C compiler
  "/opt/ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc"
  is not able to compile a simple test program.

  It fails with the following output:

   Change Dir: /home/steve/mobile_progs/linux_pjsip/build/debug/CMakeFiles/CMakeTmp

  Run Build Command:/usr/bin/gmake "cmTryCompileExec379796592/fast"

  /usr/bin/gmake -f CMakeFiles/cmTryCompileExec379796592.dir/build.make
  CMakeFiles/cmTryCompileExec379796592.dir/build

  gmake[1]: Entering directory
  `/home/steve/mobile_progs/linux_pjsip/build/debug/CMakeFiles/CMakeTmp'

  /usr/bin/cmake -E cmake_progress_report
  /home/steve/mobile_progs/linux_pjsip/build/debug/CMakeFiles/CMakeTmp/CMakeFiles
  1

  Building C object
  CMakeFiles/cmTryCompileExec379796592.dir/testCCompiler.c.o

  /opt/ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
  -o CMakeFiles/cmTryCompileExec379796592.dir/testCCompiler.c.o -c
  /home/steve/mobile_progs/linux_pjsip/build/debug/CMakeFiles/CMakeTmp/testCCompiler.c

  Linking C executable cmTryCompileExec379796592

  /usr/bin/cmake -E cmake_link_script
  CMakeFiles/cmTryCompileExec379796592.dir/link.txt --verbose=1

  /opt/ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
  CMakeFiles/cmTryCompileExec379796592.dir/testCCompiler.c.o -o
  cmTryCompileExec379796592 -rdynamic 

  /opt/android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld:
  error: cannot open crtbegin_dynamic.o: No such file or directory


  /opt/android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld:
  error: cannot open crtend_android.o: No such file or directory

  /opt/android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld:
  error: cannot find -lc

  /opt/android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld:
  error: cannot find -ldl

  collect2: error: ld returned 1 exit status

  gmake[1]: *** [cmTryCompileExec379796592] Error 1

  gmake[1]: Leaving directory
  `/home/steve/mobile_progs/linux_pjsip/build/debug/CMakeFiles/CMakeTmp'

  gmake: *** [cmTryCompileExec379796592/fast] Error 2

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:4 (project)

在事先非常感谢,

推荐答案

我设法先收拾一下这个网站来解决这个问题:

I managed to solve the problem by first going to this website:

http://developer.android.com/tools/sdk/ndk/index.html

有是使用自带的NDK独立工具链的一个例子。

There is an example of using the standalone toolchain that comes with NDK.

make-standalone-toolchain.sh --toolchain=arm-linux-androideabi-4.8

在提取到我的/ opt目录。

Extracted the into my /opt directory.

和使用此示例工具链的CMake文件

And using this sample toolchain cmake file

# Target system
set(CMAKE_SYSTEM_NAME  Android)

set(CMAKE_SYSTEM_VERSION 1)

# Compiler to build for the target
set(CMAKE_C_COMPILER /opt/arm-linux-androideabi-4.8/bin/arm-linux-androideabi-gcc)
set(CMAKE_CXX_COMPILER /opt/arm-linux-androideabi-4.8/bin/arm-linux-androideabi-g++)

一切之后只是工作。但是,我不能让我的previous问题的工作。也许我错误地设置了一些环境变量,以错误的路径。

Everything just worked after that. However, I couldn't get my previous problem working. Maybe I have set some environmental variables incorrectly to the wrong paths.

希望这可以帮助其他人。

Hope this helps someone else.

这篇关于构建工具链与cmake的交叉编译为Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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