crtbegin_so.o missing for android toolchain (custom build)

岁酱吖の 提交于 2019-12-03 14:06:59

The issue arises on NDK r7c for linux as well.

I found that the toolchain ignores the platform location ($NDK_ROOT/platforms/android-8/arch-arm/usr/lib/) and searches for it in the toolchain path, which is incorrect.

However, as the toolchain also searches for the file in the current directory, one solution is to symlink the correct platform crtbegin_so.o and crtend_so.o into the source directory:

cd src && ln -s NDK_ROOT/platforms/android-8/arch-arm/usr/lib/crtbegin_so.a

cd src && ln -s NDK_ROOT/platforms/android-8/arch-arm/usr/lib/crtend_so.a

Thus your second point should work out (where you can do a symlink, instead of a copy)

NOTE 1:This assumes that the code is being compiled for API8 (Android 2.2) using the NDK. Please alter the path to the correct path as per your requirement.

NOTE 2:Configure flags used:

./configure \
--host=arm-linux-androideabi \
CC=arm-linux-androideabi-gcc \
CPPFLAGS="-I$NDK_ROOT/platforms/android-8/arch-arm/usr/include/" \
CFLAGS="-nostdlib" \
LDFLAGS="-Wl,-rpath-link=$NDK_ROOT/platforms/android-8/arch-arm/usr/lib/ -L$NDK_ROOT/platforms/android-8/arch-arm/usr/lib/" \
LIBS="-lc"
Jeff Archer

I have found that adding --sysroot=$(SYSROOT) to the compiler options fixes the error:

cannot open crtbegin_so.o: No such file or directory

from my makefile...

CC= $(CROSS_COMPILE)gcc -fvisibility-hidded $(INC) $(LIB) -shared

Note: this assumes that the setenv-android.sh has been run to setup the environment
$. ./setenv-android.sh

In my case quotes were missing from sysroot path. When I changed

--sysroot=${ANDROID_NDK}\platforms\android-17\arch-arm

to

--sysroot="${ANDROID_NDK}\platforms\android-17\arch-arm" 

the project was compiled and linked successfully.

I faced with the same issue in two separate cases:

  1. during building boost for android
  2. during using android-cmake project.

Once I have switched to standalone toolchain issue gone, here is example of command which prepare standalone toolchain

$NDK_ROOT/build/tools/make-standalone-toolchain.sh --platform=android-9 --install-dir=android-toolchain --ndk-dir=$NDK_ROOT --system=darwin-x86_64 --toolchain=arm-linux-androideabi-4.9

Boost specific

for boost you need specify --sysroot several times in your jam

<compileflags>--sysroot=$NDK_ROOT/platforms/android-9/arch-arm
<linkflags>--sysroot=$NDK_ROOT/platforms/android-9/arch-arm
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!