* * *

Author Topic: Cross compiling: A myth?  (Read 6738 times)

radioman

  • New member
  • *
  • Posts: 33
Cross compiling: A myth?
« on: September 15, 2011, 05:47:10 pm »
I'm in the process to port a pair of Delphi applications to Lazarus to get really multiplatform applications.

Porting Delphi code to Lazarus have been proved to be an exercise of pain and frustration. They are so close each other that seems an easy task but the "little" differences in the behaviour of Delphi and Lazarus components requires a long time to test the application looking for "bugs" and workarounds.

Now I'm at the problematic part: Crosscompiling

Can Lazarus made multiplatform application or it is just a myth?

I googled a lot, finding only people like me asking how to do. I also find people pointing the other people to the wiki, but the info on the wiki is almost a joke:

Quote
Basic Steps

There are a few common steps involved in crosscompiling that you must do in every case:

    1.- Have already a FreePascal compiler for the platform you wish to compile from.

Well, I have Lazarus working so I assume I have a FreePascal compiler.

Quote
    You need to have the FreePascal source code (except for the special case of having everything prepared by someone else).

No problem. I got it from http://sourceforge.net/projects/freepascal/files/Source/2.4.2/fpc-2.4.2.source.zip

Quote
You need to either build from source or obtain binaries of the cross-binutils that run on the platform you are on and are designed to build programs for your desired target platform.

Are this code in fpc source? Or I need something else?

Quote
Sometimes you will need some files from the target you are compiling to.

Sometimes? What "sometimes" means here? what files?

Quote
From Windows
Win32 To Win64

If you are compiling the 2.1.1 or greater branch of fpc you can just do:

$ make all OS_TARGET=win64 CPU_TARGET=x86_64

and then

$ make crossinstall OS_TARGET=win64 CPU_TARGET=x86_64

Where? In FPC source directory? In C:\lazarus\fpc\2.4.2\source? Must I install FPC sources there? What directories must I have in the PATH? And then, how to tell Lazarus to compile for each platform? I tried everything I see in Internet and nothing worked.

I tried also to install Lazarus win32 in c:\lazarus32 and Lazarus win64 in c:\lazarus64 but fails because they are the same program! Note to Lazarus developers: Made both programs independent between them so you can install both lazarus and compile and debug both 32 and 64 binaries in the same machine.

The only way I have found to work is:

1.- Install lazarus-0.9.30-fpc-2.4.2-win32
2.- Compile and test/debug your program
3.-Save your application's 32 bit executable somewhere
4.- Uninstall lazarus-0.9.30-fpc-2.4.2-win64
5.- Compile and test/debug your program
6.-Save your application's 64 bit executable somewhere

Of course not the best way, because no Linux / OSX versions can be made in this way unless you repeat the above steps on a Linux (virtual?) machine to get Linux 32 and 64 bit versions.

So, my questions:

Is it possible in the real world to configure Lazarus for multiplatform / cross compiling?

Is there any real step by step guide to do so? Where?

Taking into account most Delphi projects can be tweaked to made it work under Wine / Paralells, I don't know if  the effort to port the applications to Lazarus will be worth it.

Any ideas?

Thank you in advance.
« Last Edit: September 15, 2011, 05:51:33 pm by radioman »

User137

  • Hero Member
  • *****
  • Posts: 503
Re: Cross compiling: A myth?
« Reply #1 on: September 15, 2011, 06:09:57 pm »
For what i have read, easiest solution is maybe to actually have the operating systems you are compiling to. Either multiboot/many computers or Virtual PC. You can then install Lazarus on those systems and compile normally from the same source code.

radioman

  • New member
  • *
  • Posts: 33
Re: Cross compiling: A myth?
« Reply #2 on: September 15, 2011, 06:37:59 pm »
For what i have read, easiest solution is maybe to actually have the operating systems you are compiling to.

Thank you, but that is exactly the solution I want to avoid.

typo

  • Hero Member
  • *****
  • Posts: 1368
Re: Cross compiling: A myth?
« Reply #3 on: September 15, 2011, 06:55:54 pm »
How would you test your applications?

radioman

  • New member
  • *
  • Posts: 33
Re: Cross compiling: A myth?
« Reply #4 on: September 15, 2011, 07:08:40 pm »
How would you test your applications?
Betatesters, as usually.

CaptBill

  • Sr. Member
  • ****
  • Posts: 261
Re: Cross compiling: A myth?
« Reply #5 on: September 15, 2011, 07:12:06 pm »
For what i have read, easiest solution is maybe to actually have the operating systems you are compiling to.

Thank you, but that is exactly the solution I want to avoid.

Sure but is that the best idea? You need a test environment anyway. Installing Lazarus on the test environment is more the way to go. Merely installing Laz will smooth out most of your potential issues. Plus you want to be able to reconfigure project settings at the platform level.

That would be a nightmare trying to test/debug without the control you get with Laz installed, I would imagine.

What would be really sweet would be some ISO images of the different target platforms for VirtualBox, with pre-installed Lazarus


BigChimp

  • Hero Member
  • *****
  • Posts: 1012
    • CheckRide remote control and other open source projects
Re: Cross compiling: A myth?
« Reply #6 on: September 15, 2011, 07:27:58 pm »
What would be really sweet would be some ISO images of the different target platforms for VirtualBox, with pre-installed Lazarus
+1
Very good idea...

CheckRide remote control and other open source projects:
https://bitbucket.org/reiniero/

Leledumbo

  • Hero Member
  • *****
  • Posts: 2989
Re: Cross compiling: A myth?
« Reply #7 on: September 15, 2011, 07:52:01 pm »
Quote
Porting Delphi code to Lazarus have been proved to be an exercise of pain and frustration. They are so close each other that seems an easy task but the "little" differences in the behaviour of Delphi and Lazarus components requires a long time to test the application looking for "bugs" and workarounds.
Welcome to Delphi->Lazarus conversion world. As Delphi apps could be written from very system dependent to very system independent way, the conversion could be very trivial (totally no hand made change required) to impossible (even with a lot of hand made changes). I've had all of them, that's why I knew it ;)
Quote
Can Lazarus made multiplatform application or it is just a myth?
Yes, of course. No, it's not a myth. If you want prepackaged solution, try CodeTyphon. I choose to build everything from source and maintain it myself, though
Quote
Are this code in fpc source? Or I need something else?
No, this is GNU binary utilities consisting of assembler and linker. This is required if cross compiling target is a platform FPC doesn't have internal assembler and/or linker yet. For now, it's other than x86/x86_64-Win32/Win64. So, if you target i386-win32 from i386-linux, you don't need this. But you do for the other way around (at least the linker).
Quote
Sometimes? What "sometimes" means here? what files?
Depending on the target. To target ELF binaries, all required libraries must exist at COMPILATION time. While this is not the case for PE targets (it could resolve them at RUNTIME).
Quote
Where? In FPC source directory? In C:\lazarus\fpc\2.4.2\source?
No, AFAIR by default it only supplies packages and rtl directories. You need the full source code containing compiler directory.
Quote
Must I install FPC sources there?
You may, but don't have to. It's however a good idea to do so if you don't change the default Free Pascal directory in environment options.
Quote
What directories must I have in the PATH?
C:\lazarus\fpc\2.4.2\bin\i386-win32, assuming you're on i386-win32.
Quote
And then, how to tell Lazarus to compile for each platform?I tried everything I see in Internet and nothing worked.
Once you have the cross compiler (ppcrossx64 if you target x86_64), now you need to build rtl and packages using that cross compiler. Just supply OS_TARGET=win64 and CPU_TARGET=x86_64 when calling make in respective directories. Use INSTALL_PREFIX=C:\lazarus\fpc\2.4.2 for installation directory, so if you do it correctly, you'll end up having units\i386-win32 and units\x86_64 there.
Quote
Is there any real step by step guide to do so? Where?
Try this.

CaptBill

  • Sr. Member
  • ****
  • Posts: 261
Re: Cross compiling: A myth?
« Reply #8 on: September 15, 2011, 08:03:41 pm »
It is a "write once build anywhere" language.
That means you can write your program from any platform., save and open the same files on another platform, and then compile on that platform.

In other words, Lazarus is intended to compile "on site" of the operating system. This means you install Lazarus on the target, open the file (created anywhere), and compile upon the target platform. After the job is done Lazarus can be uninstalled.

Not saying Lazarus can't compile directly from one platform to another, but doing THAT is over and above the promise of "write once build anywhere", and truthfully, less practical as your best approach considering you still need some way to test at the target.

I am still trying to grasp it myself so please correct me anywhere I am wrong.

radioman

  • New member
  • *
  • Posts: 33
Re: Cross compiling: A myth?
« Reply #9 on: September 15, 2011, 09:13:42 pm »
What would be really sweet would be some ISO images of the different target platforms for VirtualBox, with pre-installed Lazarus
+1
Very good idea...

It would be much better if Lazarus 64 bit could create and debug just after install 32 and 64 bit binaries, at least on windows, which runs natively 32 and 64 bits. (I don't remember if Linux 64 bit can run 32 bit binaries without install some extras)

radioman

  • New member
  • *
  • Posts: 33
Re: Cross compiling: A myth?
« Reply #10 on: September 15, 2011, 09:19:23 pm »
Yes, of course. No, it's not a myth. If you want prepackaged solution, try CodeTyphon. I choose to build everything from source and maintain it myself, though

I tried CodeTyphon. After read the instructions, run the bat file, and choose option seven, the computer spend some time compiling to end with NOTHING!. It was suposed it created the Lazarus executable, and so on, but not a single exe in Lazarus directory, so I gave up CodeTyphon.

Try this.

I'll try, but it is written for linux/unix system, so I do not expect to get it to work in any way, just as usual...

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1181
Re: Cross compiling: A myth?
« Reply #11 on: September 15, 2011, 09:49:09 pm »
I'm in the process to port a pair of Delphi applications to Lazarus to get really multiplatform applications.

Good.

Quote
Porting Delphi code to Lazarus have been proved to be an exercise of pain and frustration. They are so close each other that seems an easy task but the "little" differences in the behaviour of Delphi and Lazarus components requires a long time to test the application looking for "bugs" and workarounds.

The trouble is that if your Delphi code is not pure to Delphi designprinciples, but just "works", you first have to fix that, before you can start with the actual Lazarus porting.

Quote
Now I'm at the problematic part: Crosscompiling

Can Lazarus made multiplatform application or it is just a myth?

I've crosscompiled complete lazaruses from any to any platform. So say windows -> Mac OS X powerpc  etc.

The problem is usually that people try to do

1. Delphi- >lazarus porting
2. Windows -> platform X
3. crosscompiling

in one step.

Trust me as relative crosscompiling expert that crosscompiling is meant to optimize time efficiency for people that want to support X and Y, but master and own both platforms X and Y.

It is not meant for people owning platform X as an excuse to not buy a platform Y.
 

TurboRascal

  • Sr. Member
  • ****
  • Posts: 457
  • "Good sysadmin. Bad programmer."™
Re: Cross compiling: A myth?
« Reply #12 on: September 15, 2011, 10:03:19 pm »
What would be really sweet would be some ISO images of the different target platforms for VirtualBox, with pre-installed Lazarus
+1
Very good idea...



If someone is interested I could create such VirtualBox images if there are enough requests...

BTW I agree that setting up a crosscompiling environment is quite a painful experience :P I hope it'll work easier "from the box" some day...

And concerning Delphi porting, it's nothing unusual that it can be very hard since many programs use WinAPI and some VCL intricacies. The funny thing is, it's not even the way Delphi apps should have been written! Correctly written apps are much easier to port. Another problem is use of Delphi/Windows only components, and for that there's generally no easy (if any) cure.
Regards, Arny the Turbo Rascal
-
"The secret is to give them what they need, not what they want." - Scotty, STTNG:Relics

CaptBill

  • Sr. Member
  • ****
  • Posts: 261
Re: Cross compiling: A myth?
« Reply #13 on: September 15, 2011, 10:56:22 pm »
What would be really sweet would be some ISO images of the different target platforms for VirtualBox, with pre-installed Lazarus
+1
Very good idea...



If someone is interested I could create such VirtualBox images if there are enough requests...

BTW I agree that setting up a crosscompiling environment is quite a painful experience :P I hope it'll work easier "from the box" some day...

And concerning Delphi porting, it's nothing unusual that it can be very hard since many programs use WinAPI and some VCL intricacies. The funny thing is, it's not even the way Delphi apps should have been written! Correctly written apps are much easier to port. Another problem is use of Delphi/Windows only components, and for that there's generally no easy (if any) cure.

I think this approach would be ideal. In fact this is exactly what we need truthfully. Some installation scripts would be nice so they could be easily updated/version controlled, maybe integration with svn/git to keep track of versioning/updates. Be nice if 6 months down the road you want to use an ISO that you don't have to re-burn it to get the current version.

 Resolve to install Lazarus on both client and "server/source". It just make more practical sense. Can't imagine that I would not want to be able to debug from the target platform itself. What is the benefit other than saving installation time?


JD

  • Hero Member
  • *****
  • Posts: 639
Re: Cross compiling: A myth?
« Reply #14 on: September 15, 2011, 11:47:49 pm »
It is a "write once build anywhere" language.
That means you can write your program from any platform., save and open the same files on another platform, and then compile on that platform.

That is one of the ways I do it. I can also open the files inside a VirtualBox image of another operating system and then recompile the application for that operating system.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads