Recent

Author Topic: FPC compile for Caanoo (linux game console)  (Read 10055 times)

Yakumo500

  • New Member
  • *
  • Posts: 30
FPC compile for Caanoo (linux game console)
« on: December 16, 2010, 05:28:02 pm »
Hi,
Maybe I will buy me a Caanoo (http://en.wikipedia.org/wiki/GP2X_Caanoo). On several internet sides it says that the plattform is Linux ARM (EABI=5). So I searched a little bit and found this page: http://www.opensubscriber.com/message/fpc-devel@lists.freepascal.org/14876597.html.
The problem is that I don't know how to use this files. I hope you can help me.

Yakumo500

  • New Member
  • *
  • Posts: 30
Re: FPC compile for Caanoo (linux game console)
« Reply #1 on: December 18, 2010, 11:06:13 pm »
Well, finally I got the compiler compiled (http://wiki.lazarus.freepascal.org/Setup_Cross_Compile_For_ARM). But now I try to link .a files, which were generated with gcc or g++. But the functions are not found. I compile my source via:

fpc -Tlinux -Parm Test.pas

And the following appears:

undefined reference to `DGE_Init'

I'm shure that this function exists in the .a file.
Has someone an idea?

//Edit: This is the function header:
Code: [Select]
function DGE_Init(): Integer; cdecl; external;
« Last Edit: December 18, 2010, 11:09:36 pm by Yakumo500 »

Laksen

  • Hero Member
  • *****
  • Posts: 802
    • J-Software
Re: FPC compile for Caanoo (linux game console)
« Reply #2 on: December 19, 2010, 01:10:40 am »
Try
function DGE_Init(): Integer; cdecl; external name '_DGE_Init';

Yakumo500

  • New Member
  • *
  • Posts: 30
Re: FPC compile for Caanoo (linux game console)
« Reply #3 on: December 19, 2010, 07:59:19 am »
The same message appears. I'm not quite sure if the a file is a MS or a GNU file.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: FPC compile for Caanoo (linux game console)
« Reply #4 on: December 19, 2010, 08:48:29 am »
The cdecl modifier will automatically look for C mangled names (e.g. prepended with _), no need to specify it manually.
Quote
I'm shure that this function exists in the .a file.
Maybe... but how it's decorated? Please use objdump to see it. Anyway, I don't see anywhere you state to link with the .a. Do you use {$linklib xxx}? IMO it's better to use:
Code: [Select]
external 'libname' name 'mangled name'

Yakumo500

  • New Member
  • *
  • Posts: 30
Re: FPC compile for Caanoo (linux game console)
« Reply #5 on: December 19, 2010, 11:42:26 am »
I've tried objdump. Output:

...
DGE_System.o:     file format pe-i386
rw-r--r-- 500/513 712256 Sep 16 19:33 2010 DGE_System.o
...

Also I've tried an other way:

Code: [Select]
program test;

{$mode DELPHI}

uses dynlibs, SysUtils;

type
  TDGE_Init = function(): Integer; cdecl;

var
  hLib: TlibHandle;
  DGE_Init: TDGE_Init;

begin
  hLib:= LoadLibrary('libdge20.so');
  @DGE_Init := GetProcedureAddress(hLib, 'DGE_Init');
  DGE_Init();
  @DGE_Init := nil;
  if hLib <> 0 then UnloadLibrary(hLib);
  hLib:= 0;
end.

But if I compile it under Windows for ARM this error occurs:
arm-gph-linux-gnueabi-ld: cannot find -ldl

(libdl.so exists in the search path)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: FPC compile for Caanoo (linux game console)
« Reply #6 on: December 19, 2010, 12:07:31 pm »
Quote
I've tried objdump. Output:
Seems like you don't use it as expected. Try this one instead:
Code: [Select]
nm <.a file> | grep DGE_Init
Quote
But if I compile it under Windows for ARM this error occurs:
arm-gph-linux-gnueabi-ld: cannot find -ldl
Try using -Fl compiler option

Yakumo500

  • New Member
  • *
  • Posts: 30
Re: FPC compile for Caanoo (linux game console)
« Reply #7 on: December 19, 2010, 12:15:42 pm »
Sorry I've never used objdump before. This is the output:

File STDIN:
0000002c T __Z8DGE_Initv

I'm already using the -Fl compiler option in fpc.cfg which points at the directory where libdl.so is.

Yakumo500

  • New Member
  • *
  • Posts: 30
Re: FPC compile for Caanoo (linux game console)
« Reply #8 on: December 19, 2010, 01:48:14 pm »
Ok it seems that i've forgotten -Fl  :-[. Now I'm renaming the .so files. I hope it'll work.
Thank you for your support.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: FPC compile for Caanoo (linux game console)
« Reply #9 on: December 19, 2010, 01:56:27 pm »
Quote
File STDIN:
0000002c T __Z8DGE_Initv
Looks like a C++ (g++ to be precise) mangled symbol. FPC currently can't link directly to C++ modules due to non-standard mangling mechanism. "Flatten" in to C first, then link to it. Detailed explanation can be found here.

Yakumo500

  • New Member
  • *
  • Posts: 30
Re: FPC compile for Caanoo (linux game console)
« Reply #10 on: December 19, 2010, 02:18:30 pm »
Yeah I compiled it!  :D
I used the code I posted before with LoadLibrary. I had to replace some .so files which were pointing at other .so files.

 

TinyPortal © 2005-2018