Recent

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

Laksen

  • Hero Member
  • *****
  • Posts: 614
    • J-Software
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #15 on: October 31, 2011, 01:34:03 pm »
Try this:
Run fpc -Tlinux -Parm -XParm-linux- -FL/system/bin/linker -sh libtest.dpr
Then remove "/system/bin/linker" from the input section in link.res
Then run ppas.sh

It seems that the dynamic linker is called something else on Android, and that fpc puts the dynamic linker as an input to the linker script(line 439 in t_linux.pas). As far as I know it should only specify the dynamic linker as a parameter to ld, and not as an input

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7224
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #16 on: October 31, 2011, 01:36:09 pm »
It does worry me a bit that it says it can't find explicitely /lib/ld-linux.so.3 and not "just" ld-linux.so.3

I think the -XR option was added because of similar problems, see

http://lazarus.freepascal.org/index.php/topic,8084.msg57377.html#msg57377

You need to build a tree structure like on the target device, and then pass the root using -XR. 

In general, search "sheeva" threads, they contain a few msgs of me and Jonas with a lot of cross-arm experience in them.

chronozphere

  • New member
  • *
  • Posts: 41
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #17 on: November 01, 2011, 10:25:27 am »
Thank you for all the help. Much appreciated!

@Laksen: That works great! I have got my hello world sample working on android! So it goes like this. I assume you have the basic project framework allready set up, that loads a native lib and does a JNI call on it:

1. Create a dpr in the project/jni directory
2. Add jni.pas over there, include it and write a jni function
3. run: fpc -Tlinux -Parm -XParm-linux- -FL/system/bin/linker -olibyourproject.so -sh yourproject.dpr (replace "yourproject" by a different name)
4. Remove "/system/bin/linker" from the input section in link.res
5. Run chmod u+x ppas.sh (just to make sure it can execute).
6. Run ppas.sh
7. Move lib<yourproject>.so to project/libs/armeabi (make this dir if nonexistent)
6. cd to your project dir and execute "ant install" (make sure your device/emulator is connected and running).

Now you can start the app in your device. I will provide a working example later.

Quote
It seems that the dynamic linker is called something else on Android, and that fpc puts the dynamic linker as an input to the linker script(line 439 in t_linux.pas). As far as I know it should only specify the dynamic linker as a parameter to ld, and not as an input

Do you mean that ld-linux.so.3 is the default used by FPC, while android uses /system/bin/linker? I have found the latter on my device. :)
So the solution was to override this default by generating a linker script. I only don't really know what link.res is and why I needed to remove /system/lib/linker.

Would it be possible to make this build process a bit simpler? I tried removing -sh but then it complained that /system/bin/linker was not there. Is there a way to tell FPC that I'm cross-compiling so that it doesn't look for the dynamic linker on the host machine?

Thanks alot!

Laksen

  • Hero Member
  • *****
  • Posts: 614
    • J-Software
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #18 on: November 01, 2011, 01:08:08 pm »
Would it be possible to make this build process a bit simpler?
Yes, if the method I suggested is correct. You should probably test it, to see if you can still load shared libraries on the platform

chronozphere

  • New member
  • *
  • Posts: 41
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #19 on: November 02, 2011, 10:28:46 am »
Would it be possible to make this build process a bit simpler?
Yes, if the method I suggested is correct. You should probably test it, to see if you can still load shared libraries on the platform

I'm not sure what you mean. I actually used your method described in your last post and it let me dynamically link my pascal-written library to the java app running in the JVM. Do you mean loading native shared libs from native code?

Laksen

  • Hero Member
  • *****
  • Posts: 614
    • J-Software
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #20 on: November 02, 2011, 11:19:17 am »
Would it be possible to make this build process a bit simpler?
Yes, if the method I suggested is correct. You should probably test it, to see if you can still load shared libraries on the platform

I'm not sure what you mean. I actually used your method described in your last post and it let me dynamically link my pascal-written library to the java app running in the JVM. Do you mean loading native shared libs from native code?
That's what I mean, yes.

The dynamic loaded JNI functions in your case aren't ever called, so it doesn't prove very much(except that it is able to link without throwing errors)

chronozphere

  • New member
  • *
  • Posts: 41
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #21 on: November 02, 2011, 11:47:08 am »
Well, that's my fault. I didn't provide all the results I guess.

So I made this file (project/jni/hello-jni.dpr):
Code: [Select]
library hellojni;

uses
  SysUtils,
  JNI;

function Java_com_example_hellojni_HelloJni_stringFromJNI(PEnv: PJNIEnv; this: JObject): JString;
var
  I: Integer;
  S: String;
begin
    S := '';
    for I := 0 to 9 do
    begin
      S := S + IntToStr(I) + ' ';
    end;
    S := 'Lets count  '+S;
    Result := (PEnv^).NewStringUTF(PEnv, PChar(S) );
end;

exports Java_com_example_hellojni_HelloJni_stringFromJNI;

end.

I compile/link this file to get project/libs/armeabi/libhellojni.so.

The project also contains this JAVA file (project/src/com/example/hellojni/HelloJNI.java)
Code: [Select]
package com.example.hellojni;

import android.app.Activity;
import android.widget.TextView;
import android.os.Bundle;

public class HelloJni extends Activity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        TextView  tv = new TextView(this);
        tv.setText( stringFromJNI() );
        setContentView(tv);
    }

    public native String  stringFromJNI();

    static {
        System.loadLibrary("hellojni");
    }
}

If I use the steps described earlier, I will get the HelloJNI app on my tablet. When I execute it, it shows me:
Quote
Lets count 0 1 2 3 4 5 6 7 8 9

So that's definitely proof that it links and runs correctly.

But I find the build process quite cumbersome (having to edit link.res etc). Is there a way to do this in less steps?

Thanks!

Laksen

  • Hero Member
  • *****
  • Posts: 614
    • J-Software
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #22 on: November 02, 2011, 11:56:08 am »
What I meant is that the pascal program doesn't call any dynamic linked procedures. When you call NewStringUTF it simply calls a pointer which is given from the Java program

chronozphere

  • New member
  • *
  • Posts: 41
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #23 on: November 02, 2011, 12:30:03 pm »
Ok I get it. Do you have any suggestions to easily test this?
I could try to link against OpenGLESv2.so perhaps and just call eglGetDisplay(). I'll keep you posted.

Andru

  • Full Member
  • ***
  • Posts: 112
    • Homepage
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #24 on: November 03, 2011, 10:29:33 am »
Quote
But I find the build process quite cumbersome (having to edit link.res etc). Is there a way to do this in less steps?

Code: [Select]
-FLlibdl.so

Android have this one instead of ld-linux.so, so add this to your compiler options and set path to lib directory from Android NDK.

chronozphere

  • New member
  • *
  • Posts: 41
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #25 on: November 05, 2011, 05:56:15 pm »
Thanks alot. I will try this as as im back from my little holyday.
 :D

chronozphere

  • New member
  • *
  • Posts: 41
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #26 on: November 22, 2011, 11:26:17 pm »
Yes. it compiles smoothly  when using -FLlibdl.so  Thanks for that! :)

Rustam Asmandiarov

  • New member
  • *
  • Posts: 46
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #27 on: February 17, 2012, 06:57:51 am »
Hello! I compiled the application for the management and tested on the Samsung Galaxy s 2 i9100G application will not run. According tried on the emulator, just does not start, logcat brought this:
Здраствуйте! Я скомпилировал приложение по руководству и протестировал на Samsung Galaxy s 2 i9100G приложение не запустилось. По пробовал на  Эмуляторе, точно так же не запустилось, logcat вывел это:

I/lclapp  (  291): Trying to load liblclapp.so

D/dalvikvm(  291): Trying to load lib /data/data/com.pascal.lcltest/lib/liblclapp.so 0x40514330

E/lclapp  (  291): WARNING: Could not load liblclapp.so

W/System.err(  291): java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1962]:    32 could not load needed library 'ld-linux.so.3' for 'liblclapp.so' (load_library[1104]: Library 'ld-linux.so.3' not found)

W/System.err(  291):    at java.lang.Runtime.loadLibrary(Runtime.java:434)

W/System.err(  291):    at java.lang.System.loadLibrary(System.java:554)

W/System.err(  291):    at com.pascal.lcltest.LCLActivity.<clinit>(LCLActivity.java:621)

W/System.err(  291):    at java.lang.Class.newInstanceImpl(Native Method)

downloaded to the device ld-linux.so.3 not an option, since all mashines on which the library no need to install root
загружать на аппарат ld-linux.so.3 не выход, так как на всех апаратах на которых нету этой библиотеки потребуется установить root
What do I do?
lazarus: 0.9.31.33575
FPC:2.7.1
« Last Edit: February 17, 2012, 07:45:23 am by Rustam Asmandiarov »

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #28 on: February 17, 2012, 07:46:28 am »
Please do not reuse old threads for new questions. Please create a new topic.

Rustam Asmandiarov

  • New member
  • *
  • Posts: 46
Re: Cannot find /lib/ld-linux.so.3 while cross-compiling to ARM
« Reply #29 on: February 17, 2012, 07:47:45 am »
ok