10

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?

dwerner
  • 6,462
  • 4
  • 30
  • 44
  • 1
    http://stackoverflow.com/questions/7400124/cant-run-sample-rhodes-application solved it for me :) – jobwat Oct 07 '11 at 00:05

4 Answers4

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"
Samveen
  • 3,482
  • 35
  • 52
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

fantaghirocco
  • 4,761
  • 6
  • 38
  • 48
Jeff Archer
  • 79
  • 2
  • 5
  • In VS2019, as this is part of the linker phase I needed to add `--sysroot="$(SysrootLink)"` to the linker command line options – Tim MB Apr 27 '21 at 16:27
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.

Flot2011
  • 4,601
  • 3
  • 44
  • 61
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
CAMOBAP
  • 5,523
  • 8
  • 58
  • 93