Recent

Author Topic: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM  (Read 58381 times)

chronozphere

  • New Member
  • *
  • Posts: 41
Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« on: October 31, 2011, 12:32:00 am »
Hey guys,

I've ran into an issue here during my android expiriments.

I want to cross compile a library dpr to ARM to be able to use it with JNI on android. Below you will see a tiny example that reproduces the problem I'm facing now:

Code: [Select]
library hellojni;

uses
  SysUtils,
  JNI;

function Java_com_example_hellojni_HelloJni_stringFromJNI(PEnv: PJNIEnv; this: JObject): JString;
begin
    Result := (PEnv^).NewStringUTF(PEnv, 'Hello from JNI !');
end;

exports Java_com_example_hellojni_HelloJni_stringFromJNI;

end.

When I use the following command (please yell if this command is wrong somehow):
Code: [Select]
fpc -Tlinux -Parm -XParm-linux- hello-jni.dpr

I get:
Code: [Select]
Free Pascal Compiler version 2.7.1 [2011/10/27] for arm
Copyright (c) 1993-2011 by Florian Klaempfl and others
Target OS: Linux for ARMEL
Compiling hello-jni.dpr
Assembling hellojni
Linking libhello-jni.so
/usr/local/bin/arm-linux-ld: warning: link.res contains output sections; did you forget -T?
/usr/local/bin/arm-linux-ld: cannot find /lib/ld-linux.so.3
hello-jni.dpr(9,60) Error: Error while linking
hello-jni.dpr(9,60) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/local/bin/ppcarm returned an error exitcode (normal if you did not specify a source file to be compiled)

So there is a /lib/ld-linux.so.3 file which is nowhere to be found.
Code: [Select]
ls -al /lib | grep ld
gives
Code: [Select]
-rwxr-xr-x  1 root root  113964 Jan 22  2011 ld-2.11.1.so
lrwxrwxrwx  1 root root      12 Feb  2  2011 ld-linux.so.2 -> ld-2.11.1.s

So I only have version 2. I'm running Ubuntu 10.04 here.

Some extra research led me to the following website:

http://wiki.maemo.org/Compile_FreePascal_on_device

Which mentions the t_linux.pas, which is part of FPC, and refers to ld-linux.so.3. The source:
Code: [Select]
{$ifdef arm}
{$ifdef FPC_ARMEL}
     defdynlinker:='/lib/ld-linux.so.3';
{$else FPC_ARMEL}
     defdynlinker:='/lib/ld-linux.so.2';
{$endif FPC_ARMEL}
{$endif arm}

So in my case FPC_ARMEL is defined, so it selects v3. This makes sense, because this is how I've build my cross compiler:

http://wiki.lazarus.freepascal.org/Setup_Cross_Compile_For_ARM

Code: [Select]
sudo make crossinstall CPU_TARGET=arm OS_TARGET=linux CROSSBINDIR=/home/user/lazarus/fpc/binutils/ OPT=-dFPC_ARMEL INSTALL_PREFIX=/usr

So what's up here? Should I just dive in the source and change the number and rebuild my ppcarm?

Please help me find the best solution here.

Thanks a bunch! :)



Can somebody please help me out here? I'm almost there. :(

Thanks!

Laksen

  • Hero Member
  • *****
  • Posts: 621
    • J-Software
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #1 on: October 31, 2011, 01:02:11 am »
Doesn't the Android NDK have this file, or something like it?

chronozphere

  • New Member
  • *
  • Posts: 41
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #2 on: October 31, 2011, 01:08:50 am »
Well, when I go into the NDK directory and do find . -iname ld* I get:
Code: [Select]
nathan@nathan-PC android-ndk-r6b $ find . -iname ld*
./platforms/android-9/arch-x86/usr/include/asm/ldt.h
./toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/arm-linux-androideabi/lib/ldscripts
./toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/arm-linux-androideabi/bin/ld
./toolchains/x86-4.4.3/prebuilt/linux-x86/i686-android-linux/lib/ldscripts
./toolchains/x86-4.4.3/prebuilt/linux-x86/i686-android-linux/bin/ld

I did "ld -v" for both of them and they are version 2.20.1. Should I do anything with these?

Laksen

  • Hero Member
  • *****
  • Posts: 621
    • J-Software
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #3 on: October 31, 2011, 01:34:47 am »
Those are executable binaries of the binutils linker, ld. That's not what you are looking for

It needs to link to ld-linux.so.3 for the target platform, not your host platform. Try to remove sysutils from the uses clause and see if that changes anything. I don't remember ld-linux.so being a normal dependency unless you rely on dynamic linking

herux

  • Full Member
  • ***
  • Posts: 100
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #4 on: October 31, 2011, 05:54:55 am »
I hope this can help.
do this :

#apt-file search ld-linux.so.3

result on my ubuntu 11.10

libc6-armel-cross: /usr/arm-linux-gnueabi/lib/ld-linux.so.3
libc6-armhf-cross: /usr/arm-linux-gnueabihf/lib/ld-linux.so.3

then ..

#sudo apt-get install libc6-armel-cross
#sudo ln -sf /usr/arm-linux-gnueabi/lib/ld-linux.so.3 /lib/ld-linux.so.3

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #5 on: October 31, 2011, 09:04:54 am »
It needs to link to ld-linux.so.3 for the target platform, not your host platform. Try to remove sysutils from the uses clause and see if that changes anything. I don't remember ld-linux.so being a normal dependency unless you rely on dynamic linking

SysUtils does not have any external dependencies, probably the JNI unit has.

As an example of why I am sure: LCL-Android currently has zero external dependencies and it uses a lot of RTL units. But it does not use JNI. Eventually I will have to add opengl as an external dependency, however.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7510
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #6 on: October 31, 2011, 09:25:02 am »
Use -FL to specify the name of the dynamic linker.

chronozphere

  • New Member
  • *
  • Posts: 41
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #7 on: October 31, 2011, 09:40:53 am »
Thanks for all your replies!

Quote
SysUtils does not have any external dependencies, probably the JNI unit has.
Nope, my jni.pas has no uses-clause.

I've tried:
Code: [Select]
fpc -Tlinux -Parm -XParm-linux- -FL/lib/ld-linux.so.2 libtest.dpr
Which gives me:
Code: [Select]
Free Pascal Compiler version 2.7.1 [2011/10/27] for arm
Copyright (c) 1993-2011 by Florian Klaempfl and others
Target OS: Linux for ARMEL
Compiling libtest.dpr
Assembling test
Linking liblibtest.so
/usr/local/bin/arm-linux-ld: warning: link.res contains output sections; did you forget -T?
/usr/local/bin/arm-linux-ld: skipping incompatible /lib/ld-linux.so.2 when searching for /lib/ld-linux.so.2
/usr/local/bin/arm-linux-ld: cannot find /lib/ld-linux.so.2
libtest.dpr(11) Error: Error while linking
libtest.dpr(11) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/local/bin/ppcarm returned an error exitcode (normal if you did not specify a source file to be compiled)

So the version installed on my system is obviously not usable (because it's x86 instead of ARM right?)

The question is: where to get this ld-linux.so.3? It doesn't seem to exist in the 10.04 repositories (apt-file search gives nothing).

My guess is that it's in the android-ndk because C must also use it. However, I haven't been able to find it.

Code: [Select]
nathan@nathan-PC arch-arm $ pwd
/home/nathan/android/android-ndk-r6b/platforms/android-4/arch-arm
nathan@nathan-PC arch-arm $ find . -iname *so
./usr/lib/libGLESv1_CM.so
./usr/lib/libthread_db.so
./usr/lib/liblog.so
./usr/lib/libm.so
./usr/lib/libdl.so
./usr/lib/libstdc++.so
./usr/lib/libz.so
./usr/lib/libc.so
nathan@nathan-PC arch-arm $

I'm also slightly confused. When I compiled the binutils for arm, it also generated a linker (/usr/local/bin/arm-linux-ld). What is the difference between that one and the ld-linux.so.3 file I'm looking for right now?

Many thanks :)
« Last Edit: October 31, 2011, 09:53:08 am by chronozphere »

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #8 on: October 31, 2011, 10:47:14 am »
Nope, my jni.pas has no uses-clause.

What does that have to do with external dependencies? External dependencies means depending on external libraries, usually by declaring a procedure as external, but there is also {$linklib} and some other ways to add external dependencies. this is totally unrelated to the uses clause. And clearly your JNI unit has external dependencies.

chronozphere

  • New Member
  • *
  • Posts: 41
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #9 on: October 31, 2011, 11:20:48 am »
Sorry my bad. It obviously depends on a few functions exported by the JAVA Virtual machine.

However, I did some other tests and the ld-linux.so.3 requirement doesn't seem to be related to jni.pas. If I use the following example:

Code: [Select]
library test;

begin
  Writeln('a');   
end.

with the command:

Code: [Select]
fpc -Tlinux -Parm -XParm-linux- libtest.dpr

it still returns:

Code: [Select]
Free Pascal Compiler version 2.7.1 [2011/10/27] for arm
Copyright (c) 1993-2011 by Florian Klaempfl and others
Target OS: Linux for ARMEL
Compiling libtest.dpr
Assembling test
Linking liblibtest.so
/usr/local/bin/arm-linux-ld: warning: link.res contains output sections; did you forget -T?
/usr/local/bin/arm-linux-ld: cannot find /lib/ld-linux.so.3
libtest.dpr(6) Error: Error while linking
libtest.dpr(6) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/local/bin/ppcarm returned an error exitcode (normal if you did not specify a source file to be compiled)

If I replace "library" with "program" it does work. So the fact that I'm trying to compile a library causes this.

Any other ideas?

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #10 on: October 31, 2011, 11:25:26 am »
Any other ideas?

Copy ld-linux.so.3 from our telephone (or tablet or emulator) and when compiling the project pass the path to it in the -FL part

chronozphere

  • New Member
  • *
  • Posts: 41
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #11 on: October 31, 2011, 11:41:44 am »
I connected my tablet and did:
Code: [Select]
nathan@nathan-PC ~ $ adb pull /lib/ld-linux.so.3 ~
remote object '/lib/ld-linux.so.3' does not exist
So it either doesn't exist or I just don't have access to it. The latter seems likely because I can't cd into /lib

I'll see if I can get it out of the emulator.

Update: I need to "root" either my device or the emulator to get to this file. I'll have a look at this later.

I'm still not sure whether this is right. I only want to get a JNI hello world sample working. If I get my hands on this ld-linux.so.3 file on my device, there is no guarantee that my demo will still work on other devices/versions of android, right?
« Last Edit: October 31, 2011, 11:53:13 am by chronozphere »

Laksen

  • Hero Member
  • *****
  • Posts: 621
    • J-Software
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #12 on: October 31, 2011, 12:06:27 pm »
Have you tried herux's tip?

chronozphere

  • New Member
  • *
  • Posts: 41
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #13 on: October 31, 2011, 12:24:25 pm »
Yes, sorry forgot to mention it.

On my system, "apt-file search ld-linux.so.3" doesn't return any results. I did do "apt-file update". They don't seem to have libc6-armel-cross for 10.04 (only for 10.10 and up).

It seems like that's the solution to my problem. But I hate having to do a system upgrade (with all kinds of possible nasty sideeffects) just to be able to cross compile. Maybe I can build that from source somehow?
« Last Edit: October 31, 2011, 01:09:05 pm by chronozphere »

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #14 on: October 31, 2011, 01:03:21 pm »
I'm still not sure whether this is right. I only want to get a JNI hello world sample working. If I get my hands on this ld-linux.so.3 file on my device, there is no guarantee that my demo will still work on other devices/versions of android, right?

If ld-linux.so.3 was incompatible across multiple Android devices then JNI applications would not work, but this is not true, there are tons of JNI applications in the market and they work in all devices.