Recent

Author Topic: [Tutorial] Cross Compile for arm-linux (Finally it works!)  (Read 179084 times)

Kjooow

  • Jr. Member
  • **
  • Posts: 90
Re: [Tutorial] Cross Compile for arm-linux (Finally it works!)
« Reply #60 on: May 17, 2010, 04:06:17 pm »
Try with:

mkdir /media/sd/libcross/
cp /lib/* /media/sd/libcross/
cp /usr/lib/* /media/sd/libcross/

Where /media/sd/ is the path of the sd on your arm device. Then put the SD on the pc :)

Kjooow

  • Jr. Member
  • **
  • Posts: 90
Re: [Tutorial] Cross Compile for arm-linux (Finally it works!)
« Reply #61 on: May 17, 2010, 04:14:47 pm »
/home/warlock/lazarus/fpc/binutils/ld: skipping incompatible /home/warlock/lazarus/fpc/libcross/libX11.so when searching for -lX11

i rename libX11.so.6.3.0 to libX11.so but witout effect
i search for a file libX11.a but find anyting in libcross

From:
/home/warlock/lazarus/fpc/binutils/ld: skipping incompatible /usr/lib/libX11.so when searching for -lX11
to:
/home/warlock/lazarus/fpc/binutils/ld: skipping incompatible /home/warlock/lazarus/fpc/libcross/libX11.so when searching for -lX11

Now the linker uses the right folder to search libraries: /home/warlock/lazarus/fpc/libcross/

But there are still incompatible. It seems that your target libs aren't the right ones.
Do you have grabber these files from the arm-device or from the pc-linux?

The target libs must be arm-linux compiled...

warcode

  • New Member
  • *
  • Posts: 36
Re: [Tutorial] Cross Compile for arm-linux (Finally it works!)
« Reply #62 on: May 17, 2010, 04:21:43 pm »
This is what i make

cp /media/1b1f83d3-c5f0-44b0-ae17-21b401cd081b/lib/* /home/warlock/lazarus/fpc/libcross/
cp /media/1b1f83d3-c5f0-44b0-ae17-21b401cd081b/usr/lib/* /home/warlock/lazarus/fpc/libcross/

but i get the same error

/home/warlock/lazarus/fpc/binutils/ld: skipping incompatible /usr/lib/libX11.so when searching for -lX11
/home/warlock/lazarus/fpc/binutils/ld: skipping incompatible /usr/lib/libX11.a when searching for -lX11
/home/warlock/lazarus/fpc/binutils/ld: cannot find -lX11
project1.lpr(16,32) Error: Error while linking
project1.lpr(16,32) Fatal: There were 1 errors compiling module, stopping

Does i need to make clean & make ? i have a  /etc/fpc.cfg and a home/warlock/.fpc.cfg everthing is ok here ?
i will restart from beginning again :)
plz loading ...

Christian F





Kjooow

  • Jr. Member
  • **
  • Posts: 90
Re: [Tutorial] Cross Compile for arm-linux (Finally it works!)
« Reply #63 on: May 17, 2010, 05:32:03 pm »
This is what i make

cp /media/1b1f83d3-c5f0-44b0-ae17-21b401cd081b/lib/* /home/warlock/lazarus/fpc/libcross/
cp /media/1b1f83d3-c5f0-44b0-ae17-21b401cd081b/usr/lib/* /home/warlock/lazarus/fpc/libcross/

but i get the same error

/home/warlock/lazarus/fpc/binutils/ld: skipping incompatible /usr/lib/libX11.so when searching for -lX11
/home/warlock/lazarus/fpc/binutils/ld: skipping incompatible /usr/lib/libX11.a when searching for -lX11
/home/warlock/lazarus/fpc/binutils/ld: cannot find -lX11
project1.lpr(16,32) Error: Error while linking
project1.lpr(16,32) Fatal: There were 1 errors compiling module, stopping

Does i need to make clean & make ? i have a  /etc/fpc.cfg and a home/warlock/.fpc.cfg everthing is ok here ?
i will restart from beginning again :)
plz loading ...

Christian F

It seems that your lazarus doesn't use the right path again...

if the error is: /home/warlock/lazarus/fpc/binutils/ld: skipping incompatible /usr/lib/etc. etc.
it doesn't use the right path

if the error is: /home/warlock/lazarus/fpc/binutils/ld: skipping incompatible /home/warlock/lazarus/fpc/libcross/etc. etc.
it uses the right path, but it doesn't use the right libs.

I don't know why, on your installation, sometimes the path is right, sometimes not...

warcode

  • New Member
  • *
  • Posts: 36
Re: [Tutorial] Cross Compile for arm-linux (Finally it works!)
« Reply #64 on: May 17, 2010, 06:09:36 pm »
I got it finnaly i was able to compile a simple form for ARM Youpi and thanks for the help.
After pass 30 min to rename a buch of so.0.2 -> .so everything is ok now

My main application is a shop barcode scanner using overo air (wireless & bluetooth)
This application need to connect to a mysql5 database on my locale network so i'm using a TMySQL50Connection , ect  this application only have a few button and this compoment. when i try to compile it i got this

registersqldb.pas(45,3) Fatal: Can't find unit propedits used by registersqldb

Can someone give me a tpis on how using mysql database and arm ?

Many Thanks again for the help
Christian F

Kjooow

  • Jr. Member
  • **
  • Posts: 90
Re: [Tutorial] Cross Compile for arm-linux (Finally it works!)
« Reply #65 on: May 17, 2010, 06:23:14 pm »
I got it finnaly i was able to compile a simple form for ARM Youpi and thanks for the help.
After pass 30 min to rename a buch of so.0.2 -> .so everything is ok now

My main application is a shop barcode scanner using overo air (wireless & bluetooth)
This application need to connect to a mysql5 database on my locale network so i'm using a TMySQL50Connection , ect  this application only have a few button and this compoment. when i try to compile it i got this

registersqldb.pas(45,3) Fatal: Can't find unit propedits used by registersqldb

Can someone give me a tpis on how using mysql database and arm ?

Many Thanks again for the help
Christian F


I'm glad to know that it works now.

The component that you use for mysql, works well con i386-linux compiling?
If yes, try to recompile LCL and Package registration:
http://wiki.lazarus.freepascal.org/Setup_Cross_Compile_For_ARM#Configure_Lazarus_for_cross_Compile
(paragraph "Configure Lazarus for cross Compile" only)

thierrybo

  • Full Member
  • ***
  • Posts: 143
Re: [Tutorial] Cross Compile for arm-linux (Finally it works!)
« Reply #66 on: May 17, 2010, 07:36:49 pm »
Hi,

after experimenting I have some suggestions to improve wiki :

- Binutils.

I don't understand how yo install them. You unpack in one directory, install in a second directory (default location), then link back from there to a third directory. Just install in the base directory you choose for toolchain. For the directories assume you have sources in ~/lazarus/fpcsrc and install all binaries in ~/lazarus/fpc :

Code: [Select]
./configure --target=arm-linux --disable-werror --prefix=~/lazarus/fpc/binutils
make
make install


- Compile FPC from sources.

I think this part is over complicated. As for binutils, you install is /usr/, then you have some lines to erase/replace some older files with the new one from source, then link some files back to you home directory.  Either install in /usr/local/ or /opt/ or somewhere in you home folder. For example say we install in ~/lazarus/fpc as above

Code: [Select]
cd ~/lazarus/fpcsrc
make all OPT='-gl -O3p3' PP=/usr/bin/ppc386
make install FPC=/usr/bin/ppc386 INSTALL_PREFIX=~/lazarus/fpc
ln -s ~/lazarus/fpcsrc/lib/fpc/2.5.1/ppc386 ~/lazarus/fpc/bin/ppc386

- FPC for ARM

It would be useful to indicate that it is safe to install a crosscompiler in the same directory as regular freepascal.  When you crossinstall, make does not copy anything in the /bin directory, only units for the new $TARGET in  /lib/fpc/$FPCVERSION/units/$FPCTARGET and the new compiler in /lib/fpc/$FPCVERSION/newcrosscompiler.

Also using BINUTILSPREFIX combined with a masterfully created fpc.cfg we can build a powerful crosscompiling system that autoselect the right targets and avoid to set manually some options :

Code: [Select]
cd ~/lazarus/fpcsrc/
make clean crossinstall CPU_TARGET=arm OS_TARGET=linux CROSSBINDIR=~/lazarus/fpc/binutils/bin BINUTILSPREFIX=arm-linux- OPT=-dFPC_ARMEL INSTALL_PREFIX=~/lazarus/fpc PP=/usr/bin/ppc386

ln -s ~/lazarus/fpc/lib/fpc/2.5.1/ppcrossarm ~/lazarus/fpc/bin

- fpc.cfg

it is simpler to use a whole fpc.cfg in your home directory than to use INCLUDE, it is confusing. Either edit /etc/fpc.cfg or use ~/.fpc.cfg.

With the following fpc.cfg excerpt ( most retrieved from the default one installed with deb packages from freepascal site) you cover almost all situations and you don't need to specify -k and -L options in Lazarus, they will be automatically selected.

Code: [Select]
#IFNDEF CPUI386
  #IFNDEF CPUAMD64
    #DEFINE NEEDCROSSBINUTILS
  #ENDIF
#ENDIF


#IFNDEF linux
  #DEFINE NEEDCROSSBINUTILS
#ENDIF


#IFDEF FPC_CROSSCOMPILING
  #IFDEF NEEDCROSSBINUTILS
    # other binutils directory if processor or target OS differs
    -FD/home/USER/lazarus/fpc/binutils/bin
    #set prefix to select the right ones from that directory
    -XP$fpctarget-
    # other library
    -Fl/home/user/lazarus/fpc/libcross
  #ENDIF NEEDCROSSBINUTILS
#ENDIF

#IFDEF VER2_2_4
  #IFDEF FPCAPACHE_1_3
  -Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/httpd13/
  #ELSE
  #IFDEF FPCAPACHE_2_0
    -Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/httpd20
  #ELSE
    -Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/httpd22
  #ENDIF
  #ENDIF
  
  # searchpath for units and other system dependent things
  -Fu/usr/lib/fpc/$fpcversion/units/$fpctarget
  -Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/*
  -Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/rtl

#ELSE
#++++++++++++++++++++++++++++++++++++++++++++++++++++
# for custom FPC version installed in ~/lazarus/fpc
#++++++++++++++++++++++++++++++++++++++++++++++++++++
  #IFDEF FPCAPACHE_1_3
  -Fu/home/USER/lazarus/fpc/lib/fpc/$FPCVERSION/units/$FPCTARGET/httpd13/
  #ELSE
  #IFDEF FPCAPACHE_2_0
    -Fu/home/USER/lazarus/fpc/lib/fpc/$FPCVERSION/units/$FPCTARGET/httpd20
  #ELSE
    -Fu/home/USER/lazarus/fpc/lib/fpc/$FPCVERSION/units/$FPCTARGET/httpd22
  #ENDIF
  #ENDIF

  # searchpath for units and other system dependent things
  -Fu/home/USER/lazarus/fpc/lib/fpc/$FPCVERSION/units/$FPCTARGET
  -Fu/home/USER/lazarus/fpc/lib/fpc/$FPCVERSION/units/$FPCTARGET/*
  -Fu/home/USER/lazarus/fpc/lib/fpc/$FPCVERSION/units/$FPCTARGET/rtl

#ENDIF

# searchpath for libraries
#ifdef cpux86_64
  -Fl/usr/lib/gcc/x86_64-linux-gnu/4.3.3
#endif


#ifdef cpui386
-Fl/usr/lib/gcc/x86_64-linux-gnu/4.3.3
#endif

 - Lazarus

Stripping after build. If you set proper compiler options you do not need this, check -CX -XX and uncheck all in Degugging group excepting -Xs.
« Last Edit: May 23, 2010, 08:04:10 am by thierrybo »

Giarados

  • Newbie
  • Posts: 1
Re: [Tutorial] Cross Compile for arm-linux (Finally it works!)
« Reply #67 on: May 18, 2010, 06:33:37 pm »
Hi to everybody. I ve been trying to get the compiler working for three days...:( i ve been following your guide and apparently nothing went wrong..the problem is that i m unable to crosscompile any source for arm. could you help me? i don't get any error message while compiling binutils and fpc..(i m not interested in using lazaraus, just need fpc..)

thanks ;)

EDIT:
I would need to download the correct zip package..now it is unavailable..using the svn repository the procedure doesn't work maybe because the directory tree is different..could anyone help me?
« Last Edit: May 20, 2010, 01:45:30 pm by Giarados »

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: [Tutorial] Cross Compile for arm-linux (Finally it works!)
« Reply #68 on: November 30, 2010, 09:36:29 am »
CodeTyphon seems to be an easy solution for all newbies interested in cross compiling.
http://www.pilotlogic.com/sitejoom/index.php?option=com_content&view=article&id=96&catid=68&Itemid=147

Quote
• 4 CPU-Operating Systems Host Layers (Win32, Win64, Linux32, Linux64).
• 16 CPU-Operating Systems Target Layers.
• Win64 Layer has Dual Personality (Win64 and Win32).
• Win32 Layer is Cross-Build Center with Cross Elements for:
    arm-Wince
    arm-Linux
    arm-Embedded  (freepascal only)
    arm-gba            (freepascal only)
    arm-nds            (freepascal only)
    i386-Win32
    i386-Linux
    i386-FreeBSD
    i386-Haiku         (freepascal only)
    x86_64-Win64
    x86_64-Linux
    x86_64-FreeBSD
    powerpc-Linux
    powerpc64-Linux  (freepascal only)
    sparc-Linux
    sparc-Solaris      (freepascal only)
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

SONFEDAI

  • Jr. Member
  • **
  • Posts: 55
Re: [Tutorial] Cross Compile for arm-linux (Finally it works!)
« Reply #69 on: December 09, 2010, 12:15:01 pm »
iPhone Developing on Windows32 with Lazarus :)

is it Possible?
I'm using
   Lazarus: 0.9.3.1
   Date: 2011-11-05
   FPC: 2.5.1
   SVN Ver.: 29060

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: [Tutorial] Cross Compile for arm-linux (Finally it works!)
« Reply #70 on: December 11, 2010, 05:50:44 pm »
You can't develop for iOS on Windows with any IDE, not just Lazarus, because Apple's tools only run on OS X.

Thanks.

-Phil

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11444
  • FPC developer.
Re: [Tutorial] Cross Compile for arm-linux (Finally it works!)
« Reply #71 on: December 13, 2010, 02:15:23 pm »

This is what i make

cp /media/1b1f83d3-c5f0-44b0-ae17-21b401cd081b/lib/* /home/warlock/lazarus/fpc/libcross/
cp /media/1b1f83d3-c5f0-44b0-ae17-21b401cd081b/usr/lib/* /home/warlock/lazarus/fpc/libcross/

but i get the same error

/home/warlock/lazarus/fpc/binutils/ld: skipping incompatible /usr/lib/libX11.so when searching for -lX11
/home/warlock/lazarus/fpc/binutils/ld: skipping incompatible /usr/lib/libX11.a when searching for -lX11
/home/warlock/lazarus/fpc/binutils/ld: cannot find -lX11

In my crosscompiling snapshot I have:

#ifdef cpuarm
-XR/libraryimages/sheevaplug
#-CfSOFT
-dFPC_ARMEL
-Cparmv5
#-k"-mabi=apcs-gnu"
#-k"-mfpu=fpa"
#-CaEABI
-dusecthreads
-Fl/libraryimages/sheevaplug/lib
-Fl/libraryimages/sheevaplug/usr/lib
#endif

the important one here is the -XR which together with the --prefix of compiling the binutils (see below) prevented NOT searching libraries in normal dirs, and DO search dirs in the copied dirs. The -Fl's might be redundant, just like the many commented commands.
 
moreover, depending on what I am compiling for I had to set the eabi version for the assembler. I suspect the "default" eabi might work depending on which target
you used to compile your binutils (gnu-eabi is eabi 5 afaik, arm-elf is 0. I need 4 :-)

For that, on *nix (freebsd) I rename the assembler to arm-linux-as2, and make a shellscript arm-linux-as containing:

#/usr/bin/env bash
arm-linux-as2 -meabi 4 $*

For windows I use this pascal wrapper program:

http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/install/cross/aswrapper.pas?view=markup&revision=824&root=fpcbuild


my snapshot is then compiled with

----------------------------------
#!/usr/bin/env bash

PATH=/home/marcov/armelfbinutils:$PATH
export PATH

cd fpc
make crosszipinstall CPU_TARGET=arm OS_TARGET=linux OPT="-dFPC_ARMEL" CROSSOPT="-XR/libarm -dFPC_ARMEL -CfSOFT -Cparmv5" FPC=~/ppcrel
-----------

and the binutils were made using:

--------------------------------------------
#!/usr/bin/env bash

# 1. extract the binutils 2.20 .tar.bz2
#     tar xvjf binutils-2.20.tar.bz2 in the dir where it is residing now
# 2. apply the as.h.diff patch to <extractedbinutils>/gas/as.h
# 3. run this shell script
# 4. some additional renaming of the arm,as,ld (or *-new) might be necessary

# setting static

LD_FLAGS="${LD_FLAGS} -static"
LDFLAGS="${LD_FLAGS} -s"
CFLAGS="${CFLAGS} -static"
CPPFLAGS="${CPPFLAGS} -static"
CXXFLAGS="${CXXFLAGS} -static"

# configure binutils

../binutils-2.20/configure --disable-nls --disable-shared --target=arm-elf --prefix /usr/cross/

# build binutils

make

# collect binaries

TARGETDIR=/home/jerome/armelfbinutils/

mkdir -p $TARGETDIR
find . -perm /u+x -type f |grep -v status |xargs -Ireplfilename cp replfilename $TARGETDIR
--------------------

Note that the prefix is important since it seems to stop the resulting binutils from searching the normal dirs.

Sometimes compiling binutils doesn't work, (a common problem gcc version related afaik), and then I use this patch:
===================================================================
RCS file: /cvs/src/src/gas/as.h,v
retrieving revision 1.64
retrieving revision 1.64.2.1
diff -u -r1.64 -r1.64.2.1
--- src/gas/as.h   2009/09/03 12:54:21   1.64
+++ src/gas/as.h   2009/12/03 10:40:25   1.64.2.1
@@ -238,7 +238,7 @@
 #define know(p) gas_assert(p)   /* Verify our assumptions!  */
 #endif /* not yet defined */
 #else
-#define know(p)         /* know() checks are no-op.ed  */
+#define know(p)   do {} while (0)   /* know() checks are no-op.ed  */
 #endif
 
 /* input_scrub.c */

Jnny_CN

  • Newbie
  • Posts: 1
Re: [Tutorial] Cross Compile for arm-linux (Finally it works!)
« Reply #72 on: December 31, 2010, 04:42:57 am »
i was successfuly get fpc gui apps run on real s3c6410 hardware with your wiki ,thanks

i use crosstoolschain "arm-2010q1-202-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2" downloads from http://www.codesourcery.com/

with this toolchain i cross compile fpc 2.5.1 for armv5 arch

then use the fpc 2.5.1 for armv5 arch cross compile the LCL and Package

within scratchbox i cross compile the xorg server and gtk library

so all needed thing get ready,

then set the right compiler and library path with your wiki

now i can use Lazarus IDE make my gui apps run and debug under the host(win32 or linux-i386) then cross compile it under linux-i386 ,finally copy to the real hardware get it run well.

these are the main steps i have done

fpc+Lazarus is great ,it make me for more easier to write gui apps on embedded linux

than use gtk or wxwidgets(wxGTK) write gui apps on embedded linux.

thanks guys




Marcovaldo

  • New member
  • *
  • Posts: 7
Re: [Tutorial] Cross Compile for arm-linux (Finally it works!)
« Reply #73 on: January 27, 2011, 03:01:11 pm »
http://wiki.lazarus.freepascal.org/Setup_Cross_Compile_For_ARM

Hello Kjooow,

1st thx for the script (helping such newbies like me out)!

I used a virtual Ubuntu 9.10 (under VMWare, updated)
and the script ran through OK (throwing lots of warnings, but I think this
might be normal)

Under Lazarus and under fpc from the command line, I have difficulties
with the chaining to the assembler:
Quote
Free Pascal Compiler version 2.5.1 [2011/01/26] for arm
Copyright (c) 1993-2010 by Florian Klaempfl
Target OS: Linux for ARMEL
Compiling test1.lpr
Assembling test1
test1.lpr(15,16) Error: Assembler /home/kra/lazarus/fpc/binutils/as not found, switching to external assembling
test1.lpr(15,16) 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)

The X-flags etc of as look OK. I can call fpc with -s and manually
feed the results to as. This works.

usr/local/bin looks OK
Quote
.........
-rwxr-xr-x 1 root root      54 2011-01-27 05:19 arm-linux-as
-rwxr-xr-x 2 root root 3840999 2011-01-26 09:47 arm-linux-as_org
lrwxrwxrwx 1 root root      29 2011-01-26 10:00 ppcarm -> /usr/lib/fpc/2.5.1/ppcrossarm
kra@ubuntu910desktop:/usr/local/bin$ cat arm-linux-as
#!/bin/sh
/usr/local/bin/arm-linux-as_org -meabi=5 $@
kra@ubuntu910desktop:/usr/local/bin$

and /home/user/lazarus/fpc/binutils look also OK
Quote
lrwxrwxrwx 1 kra kra 27 2011-01-26 09:47 ar -> /usr/local/bin/arm-linux-ar
lrwxrwxrwx 1 kra kra 27 2011-01-27 07:08 as -> /usr/local/bin/arm-linux-as
lrwxrwxrwx 1 kra kra 27 2011-01-26 09:47 ld -> /usr/local/bin/arm-linux-l

Any idea what might went wrong?

Marcovaldo

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11444
  • FPC developer.
Re: [Tutorial] Cross Compile for arm-linux (Finally it works!)
« Reply #74 on: January 27, 2011, 10:10:51 pm »

Any idea what might went wrong?


Add -XParm-linux-

 

TinyPortal © 2005-2018