26

I used the following...

~/Development/Android/android-ndk-r8c/build/tools/make-standalone-toolchain.sh --platform=android-9 --install-dir=/Users/me/toolchain

Then I create the following code file...

int main ()
{
  return 0;
}

I tried ...

<toolchain>/arm-linux-androideabi-gcc test.c

I also tried

 <toolchain>/arm-linux-androideabi-gcc --sysroot=<toolchain>/sysroot test.c 

Both come back...

 toolchain/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot open crtbegin_dynamic.o: No such file or directory
4

4 回答 4

23

为了使它更简单,只需设置 sysroot:

<toolchain>/arm-linux-androideabi-g++ ~/test.c -o ~/test --sysroot=/home/user/android-ndk/platforms/android-9/arch-arm/
于 2013-07-11T06:24:53.823 回答
13

/arm-linux-androideabi-gcc test.c

sysroot在这个中失踪了。


/arm-linux-androideabi-gcc --sysroot=/sysroot test.c

这个,sysroot错了。它应该类似于:

--sysroot=/opt/android-ndk-r9/platforms/android-18/arch-arm

您还需要导出 LD(所有工具都应该在路径上):

$ echo $PATH
/opt/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin:
/opt/android-sdk-macosx/tools/:/opt/android-sdk-macosx/platform-tools/:/opt/local/bin:
/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
$ echo $LD
arm-linux-androideabi-ld

您可能应该导出工具链中的所有工具:

export CPP=arm-linux-androideabi-cpp
export CC=arm-linux-androideabi-gcc
export CXX=arm-linux-androideabi-g++
export LD=arm-linux-androideabi-ld
export AS=arm-linux-androideabi-as
export AR=arm-linux-androideabi-ar
export RANLIB=arm-linux-androideabi-ranlib

如果您正在处理 Autoconf 项目,请添加以下内容:

$ echo $ANDROID_SYSROOT
/opt/android-ndk-r9/platforms/android-18/arch-arm
export CPPFLAGS="--sysroot=$ANDROID_SYSROOT"
export CFLAGS="--sysroot=$ANDROID_SYSROOT"
export CXXFLAGS="--sysroot=$ANDROID_SYSROOT"
于 2014-01-09T14:06:07.893 回答
2

好的,回首往事,我根据命令为 Android-9 制作了工具链......

~/Development/Android/android-ndk-r8c/build/tools/make-standalone-toolchain.sh --platform=android-9 --install-dir=/tmp/my-toolchain

当我跑...

<install>/android-ndk-r8c$ find ./ -name crtbegin_dynamic*
.//platforms/android-14/arch-arm/usr/lib/crtbegin_dynamic.o
.//platforms/android-14/arch-mips/usr/lib/crtbegin_dynamic.o
.//platforms/android-14/arch-x86/usr/lib/crtbegin_dynamic.o
.//platforms/android-3/arch-arm/usr/lib/crtbegin_dynamic.o
.//platforms/android-4/arch-arm/usr/lib/crtbegin_dynamic.o
.//platforms/android-5/arch-arm/usr/lib/crtbegin_dynamic.o
.//platforms/android-8/arch-arm/usr/lib/crtbegin_dynamic.o
.//platforms/android-9/arch-mips/usr/lib/crtbegin_dynamic.o
.//platforms/android-9/arch-x86/usr/lib/crtbegin_dynamic.o

如您所见,由于某种原因,我安装的 android-9 没有此文件。我为 android-14 重建,一切正常。有人知道这是怎么回事吗?Bonehead 文件移动我的一部分?

于 2013-05-28T16:15:56.857 回答
0

这对我有用,我遇到了同样的问题,我试图在 NDK 中构建 gcc-4.8 工具链并遇到了同样的问题。尽管我的情况有点不同,但我是在 Android 设备上构建的,这意味着我有 Bionic库libc.solibdl.so. /system/lib配置时出现此错误libgomp

toolchain-build/binutils-2.23/ld/ld-new: cannot find crtbegin_dynamic.o: No such file or directory
toolchain-build/binutils-2.23/ld/ld-new: cannot find -lc
toolchain-build/binutils-2.23/ld/ld-new: cannot find -ldl
toolchain-build/binutils-2.23/ld/ld-new: cannot find crtend_android.o: No such file or directory

Make 文件正在-B为特定目录设置一个选项,toolchain/gcc-4.8/gcc/因此我从这两个共享库创建了符号链接/system/libgcc-4.8/gcc. 然后我符号链接到目标文件以及编译和安装到 toolchain-build/prefix/lib/gcc/arm-linux-androideabi/4.8/ crtbegin_dynamic.ofind的命令可以帮助你找到它们。crtend_android.ocrtbegin.ocrtend.othe

我用来制作符号链接的命令如下所示:

ln -s ../../prefix/lib/gcc/arm-linux-androideabi/4.8/crtend.o crtend_android.o

toolchian-build/gcc-4.8/gcc目录中,对我来说这很有效,因为那是配置指向搜索的地方,-B传递makexgcc.

我希望这对某人有所帮助。是时候继续了libatomic;)

于 2014-07-14T11:02:28.003 回答