Recent

Author Topic: Cross compiling (Win32 -> Debian)  (Read 8909 times)

Hendi48

  • Newbie
  • Posts: 3
Cross compiling (Win32 -> Debian)
« on: March 18, 2014, 03:06:22 am »
Hello,

I have a small server application (only ~130 lines) I need to run on a Debian server. Sadly Delphi still doesn't offer Linux support, and rather than rewriting the thing in Java, I want to try compiling it with Free Pascal. I downloaded CrossFPC because it comes with the required bintools and a compiled RTL. Surprisingly I was able to compile and run a simple helloworld program without major problems.

However, my program uses Indy, which seems to be slightly more complicated. It compiles fine, but linking fails :(

This is the batch file I use for compiling:
Quote
"C:\Program Files\CrossFPC\bin\i386-win32\ppc386.exe" -TLINUX -FD"C:\Program Files\CrossFPC\bin\i386-linux\" -Xs -Xd -XX -Mdelphi -FlC:\i386-linux -Fu"M:\CodeGear RAD Studio 2009\Indy 10 SVN\trunk\Lib\Core\;M:\CodeGear RAD Studio 2009\Indy 10 SVN\trunk\Lib\Protocols;M:\CodeGear RAD Studio 2009\Indy 10 SVN\trunk\Lib\System" project1.lpr

The helloworld program worked without specifying the library path, but Indy (or RTL units it uses) seems to require libc. I tried using the one that comes with CrossFPC first, but it threw a bunch of "undefined reference" errors at me. Then I downloaded the libc6-i386 package on Debian and copied the files to my local machine (and I also removed various numbers from the file extensions). I couldn't find the crt*.o files, so I took them from CrossFPC. That brought a slight improvement, since 2-3 of the reference errors disappeared.

This is the output I get:
Quote from: ppc386
Free Pascal Compiler version 2.7.1 [2013/09/08] for i386
Copyright (c) 1993-2013 by Florian Klaempfl and others
Target OS: Linux for i386
Compiling project1.lpr
project1.lpr(57,3) Note: Local variable "Path" not used
project1.lpr(57,9) Note: Local variable "CRC32" not used
project1.lpr(58,3) Note: Local variable "Buf" not used
project1.lpr(59,3) Note: Local variable "FS" not used
Linking project1
C:\i386-linux\/libdl.so: undefined reference to `_rtld_global@GLIBC_PRIVATE'
C:\i386-linux\/libc.so: undefined reference to `__libc_enable_secure@GLIBC_PRIVATE'
C:\i386-linux\/libc.so: undefined reference to `__libc_stack_end@GLIBC_2.1'
C:\i386-linux\/libdl.so: undefined reference to `_rtld_global_ro@GLIBC_PRIVATE'
C:\i386-linux\/libc.so: undefined reference to `___tls_get_addr@GLIBC_2.3'
C:\i386-linux\/libc.so: undefined reference to `_dl_argv@GLIBC_PRIVATE'
C:\i386-linux\/libdl.so: undefined reference to `_dl_rtld_di_serinfo@GLIBC_PRIVATE'
project1.lpr(131,1) Error: Error while linking
project1.lpr(131,1) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted

Any ideas? Am I missing files or is it the wrong libc version?
« Last Edit: March 18, 2014, 03:09:32 am by Hendi48 »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11446
  • FPC developer.
Re: Cross compiling (Win32 -> Debian)
« Reply #1 on: March 18, 2014, 10:36:41 am »
I hope you didn't mix files that came with crossfpc and files from your system. If you did that, erase, and copy anew.

At the very least you will need a libc, a libgcc  (or libgcc_s, often only available as .a) and crti/crtn crtbegin and crtend, ld-linux

Probably also librt.so

Hendi48

  • Newbie
  • Posts: 3
Re: Cross compiling (Win32 -> Debian)
« Reply #2 on: March 18, 2014, 05:20:11 pm »
I deleted the files I copied from CrossFPC (it was only the crt*.o files). Now I got crtbegin.o and crtend.o from gcc-4.7, crti.o and crtn.o from libc6-dev and libgcc_s.so from libgcc1. But I'm still getting the same errors.

Quote from: Library folder
23.12.2013  19:13             1.212 crt1.o
07.01.2013  05:49             1.876 crtbegin.o
07.01.2013  05:49             2.420 crtbeginS.o
07.01.2013  05:49             2.176 crtbeginT.o
07.01.2013  05:49               930 crtend.o
07.01.2013  05:49               930 crtendS.o
23.12.2013  19:13             1.012 crti.o
23.12.2013  19:13               504 crtn.o
23.12.2013  19:13             1.516 gcrt1.o
18.03.2014  02:40           121.984 ld-2.13.so
18.03.2014  02:41           121.984 ld-linux.so.2
18.03.2014  02:40             9.840 libanl-2.13.so
18.03.2014  02:41             9.840 libanl.so
18.03.2014  02:40             5.468 libBrokenLocale-2.13.so
18.03.2014  02:41             5.468 libBrokenLocale.so
18.03.2014  02:40         1.441.884 libc-2.13.so
18.03.2014  02:41         1.441.884 libc.so
18.03.2014  02:40           185.852 libcidn-2.13.so
18.03.2014  02:41           185.852 libcidn.so
18.03.2014  02:40            38.336 libcrypt-2.13.so
18.03.2014  02:41            38.336 libcrypt.so
18.03.2014  02:40             9.768 libdl-2.13.so
18.03.2014  02:41             9.768 libdl.so
07.01.2013  05:50           114.788 libgcc_s.so
18.03.2014  02:40           148.920 libm-2.13.so
18.03.2014  02:41           148.920 libm.so
18.03.2014  02:40            13.884 libmemusage.so
18.03.2014  02:40            79.652 libnsl-2.13.so
18.03.2014  02:41            79.652 libnsl.so
18.03.2014  02:40            26.372 libnss_compat-2.13.so
18.03.2014  02:41            26.372 libnss_compat.so
18.03.2014  02:40            22.008 libnss_dns-2.13.so
18.03.2014  02:41            22.008 libnss_dns.so.2
18.03.2014  02:40            42.544 libnss_files-2.13.so
18.03.2014  02:41            42.544 libnss_files.so.2
18.03.2014  02:40            17.928 libnss_hesiod-2.13.so
18.03.2014  02:41            17.928 libnss_hesiod.so.2
18.03.2014  02:40            38.476 libnss_nis-2.13.so
18.03.2014  02:41            38.476 libnss_nis.so.2
18.03.2014  02:40            46.632 libnss_nisplus-2.13.so
18.03.2014  02:41            46.632 libnss_nisplus.so.2
18.03.2014  02:40             5.580 libpcprofile.so
18.03.2014  02:41           679.340 libpthread-2.13.so
18.03.2014  02:41           679.340 libpthread.so
18.03.2014  02:40            71.408 libresolv-2.13.so
18.03.2014  02:41            71.408 libresolv.so
18.03.2014  02:40            30.608 librt-2.13.so
18.03.2014  02:41            30.608 librt.so
18.03.2014  02:40            13.780 libSegFault.so
18.03.2014  02:41            26.324 libthread_db-1.0.so
18.03.2014  02:41            26.324 libthread_db.so
18.03.2014  02:41             9.724 libutil-2.13.so
18.03.2014  02:41             9.724 libutil.so

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11446
  • FPC developer.
Re: Cross compiling (Win32 -> Debian)
« Reply #3 on: March 18, 2014, 05:34:13 pm »
My guess is that you need an -FL/lib/ld-linux.so.2 line

The problem is that on target GCC's have certain things hardcoded (or relative to prefix) that crosslinkers have not.

And of course make sure,sure,sure that everything is in the same version (as in from a working distro userland).  Quickly installing base in a Vbox and examining that (e.g. by creating a small hello world with gcc with high verbosity) can yield additional clues.

Hendi48

  • Newbie
  • Posts: 3
Re: Cross compiling (Win32 -> Debian)
« Reply #4 on: March 19, 2014, 01:25:57 am »
I gave up and compiled it on Debian itself. There it compiled & linked without complaints.

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: Cross compiling (Win32 -> Debian)
« Reply #5 on: March 19, 2014, 08:28:25 am »
I gave up and compiled it on Debian itself.
Maybe before giving up you might want to try CodeTyphon?
http://www.pilotlogic.com/sitejoom/index.php/wiki/84-wiki/codetyphon-studio/223-codetyphon-status
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

 

TinyPortal © 2005-2018