crtbegin_so.o missing for android toolchain (custom build)
Asked Answered
P

4

11

I have compiled gdc together with gcc using the android build-gcc.sh script, and have included a new stub in build/core/definitions.mk to deal with D language files as a part of the build process. I know things are compiling OK at this point, but my problem is linking:

When I build a project, I get this error:

ld: crtbegin_so.o: No such file: No such file or directory

This is true for regular c-only projects as well. Now I ran a quick find in my build directory, and found that the file (crtbegin_so.o) does exist within the sysroot I specified when I compiled gcc (or rather, when build-gcc.sh built it).

  • What are some things I could look for to find a solution to this problem?

  • Would copying the files locally and linking directly to them be a decent solution in the interim?

  • Why would ld (or collect2) be trying to include these for a gdc (D Language) linkage?

Petroglyph answered 30/7, 2011 at 4:54 Comment(1)
#7400624 solved it for me :)Illjudged
O
12

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"
Outworn answered 24/4, 2012 at 9:21 Comment(1)
This is great, thanks! Now I can build gdc against the android toolchain.Petroglyph
B
6

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

Bay answered 26/1, 2016 at 15:23 Comment(1)
In VS2019, as this is part of the linker phase I needed to add --sysroot="$(SysrootLink)" to the linker command line optionsIllbehaved
Q
2

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.

Quirt answered 24/4, 2016 at 15:27 Comment(0)
I
0

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
Incompressible answered 29/11, 2015 at 19:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.