[fpc-pascal] problem linking when using "cthreads" when cross-compiling for arm
Seth Grover
sethdgrover at gmail.com
Mon May 24 19:15:30 CEST 2010
After doing some research (mostly reading
http://wiki.lazarus.freepascal.org/Setup_Cross_Compile_For_ARM) and
experimenting, I am now cross compiling for ARM Linux from inside an
x86 Linux VM. I followed the instructions in the aforementioned link
with a few minor adjustments for my environment, and it's working
quite nicely. I am able to compile FPC programs which use various RTL
units and everything seems to compile fine and then rune fine when
copied over to my Nokia N800.
The way I set it up was to create a "/usr/local/bin/arm" directory,
with symlinks in that directory like this:
$ ls -l
total 0
lrwxrwxrwx 1 root root 15 2010-05-24 08:53 ar -> ../arm-linux-ar
lrwxrwxrwx 1 root root 15 2010-05-24 08:53 as -> ../arm-linux-as
lrwxrwxrwx 1 root root 15 2010-05-24 08:53 ld -> ../arm-linux-ld
which point to the arm-linux-* binaries that were installed when I
compiled and installed binutils for arm. I also have a
/usr/local/lib/arm directory containing the contents of my /lib and
/usr/lib directories which I copied over from my N800. Then, in
fpc.cfg I have:
#ifdef cpuarm
-Xd
-XP/usr/local/bin/arm/
-Fl/usr/local/lib/arm/
#endif
so that the regular library paths aren't used (-Xd), the binutils from
/usr/local/bin/arm/ are used (-XP) and the libraries in
/usr/local/lib/arm/ are found (-Fl). This all seems to work fine.
FWIW, the command I used to do the crossinstall was:
sudo make crossinstall CPU_TARGET=arm OS_TARGET=linux
CROSSBINDIR=/usr/local/bin/arm/ OPT=-dFPC_ARMEL
INSTALL_PREFIX=/usr/local
When I compile simple test programs everything is found Ok, even when
using a unit like systemlog which causes libc to be linked. However,
when I try to compile something that uses cthreads, I get the
following errors:
$ fpc -Parm runthreads.pas
Free Pascal Compiler version 2.4.1 [2010/05/24] for arm
Copyright (c) 1993-2009 by Florian Klaempfl
Target OS: Linux for ARMEL
Compiling runthreads.pas
runthreads.pas(25,10) Warning: Local variable "s" does not seem to be
initialized
Assembling runthreads
Linking runthreads
/usr/local/bin/arm/ld: warning: link.res contains output sections; did
you forget -T?
/usr/local/lib/fpc/2.4.1/units/arm-linux/rtl/cthreads.o: In function
`CTHREADS_LOADPTHREADS$$BOOLEAN':
cthreads.pp:(.text.n_cthreads_loadpthreads$$boolean+0xc): warning:
Using 'dlopen' in statically linked applications requires at runtime
the shared libraries from the glibc version used for linking
/usr/local/lib/arm//libdl.a(dlopen.o): In function `dlopen':
(.text+0xc): undefined reference to `__dlopen'
/usr/local/lib/arm//libdl.a(dlclose.o): In function `dlclose':
(.text+0x0): undefined reference to `__dlclose'
/usr/local/lib/arm//libdl.a(dlsym.o): In function `dlsym':
(.text+0xc): undefined reference to `__dlsym'
/usr/local/lib/arm//libdl.a(dladdr.o): In function `dladdr':
(.text+0x0): undefined reference to `__dladdr'
runthreads.pas(28,45) Error: Error while linking
runthreads.pas(28,45) 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)
Here's what I have pthread-related in my /usr/local/lib/arm directory:
$ ll libpthread*
-rw-r--r-- 1 root root 77k 2010-05-24 10:27 libpthread-2.5.so
-rw-r--r-- 1 root root 268k 2010-05-24 10:27 libpthread.a
-rw-r--r-- 1 root root 1.3k 2010-05-24 10:27 libpthread_nonshared.a
-rw-r--r-- 1 root root 245 2010-05-24 10:40 libpthread.so
lrwxrwxrwx 1 root root 17 2010-05-24 10:40 libpthread.so.0 ->
libpthread-2.5.so
$ cat libpthread.so
/* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily. */
OUTPUT_FORMAT(elf32-littlearm)
GROUP ( /usr/local/lib/arm/libpthread.so.0
/usr/local/lib/arm/libpthread_nonshared.a )
Does anyone have any suggestions?
Thanks,
-SG
--
This email is fiction. Any resemblance to actual events
or persons living or dead is purely coincidental.
Seth Grover
sethdgrover[at]gmail[dot]com
More information about the fpc-pascal
mailing list