Recent

Author Topic: cross compilation by Linux  (Read 1991 times)

mikutu

  • New Member
  • *
  • Posts: 14
cross compilation by Linux
« on: October 16, 2020, 05:20:10 am »
Need to build a project for Linux.

The source code is on your Windows computer.

When cross compilation on Windows there is bug - https://bugs.freepascal.org/view.php?id=37217

I think I need an option
- source code transfer to Linux
- build project
- transfer exe back to Windows

I didn't find a way to implement it.
Most likely, you need to use ssh.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6647
Re: cross compilation by Linux
« Reply #1 on: October 16, 2020, 08:48:09 am »
Unless your Linux system is severely resource-constrained there's very little excuse not to compile on it. If you need access to your source from multiple systems then you could install a Subversion (svn) server, probably on the linux system.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: cross compilation by Linux
« Reply #2 on: October 16, 2020, 08:52:15 am »
Surely Windows/Linux can access the other's file system over the LAN (samba) for transferring files? That's what I use for macOS/FreeBSD/Windows.

dbannon

  • Hero Member
  • *****
  • Posts: 2778
    • tomboy-ng, a rewrite of the classic Tomboy
Re: cross compilation by Linux
« Reply #3 on: October 16, 2020, 09:48:49 am »
It does make sense to try and compile your app on Linux, at least for the first time because you will need to check that it works as expected. And you might find you have used some Windows only specific things that you need to fix. So, assume you need Lazarus installed on Linux system. Please read the relevant wiki page.

To transfer your file, ssh is great on Linux, (relevantly) hard work on windows. Lots of other options.

Are your Windows and Linux boxes separate boxes or are you dual booting ?
 
First, make a zip of the source. In Lazarus, on your windows box, choose Project-> publish. Tht will make a zip file very easy to transfer to a linux box.

If you are dual booting, then boot Linux, it will mount your Windows file system, easy to find that zip file that way.

Else, as Trev said, smb is a good option, make a 'share' in windows, put the zip file there. On the Linux box, most file managers include what ever is necessary to mount a windows SMB share.

Or move the zip file to google drive, drop box or what ever ....

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

mikutu

  • New Member
  • *
  • Posts: 14
Re: cross compilation by Linux
« Reply #4 on: October 16, 2020, 10:30:08 am »
linux and windows on different computers. I compile use command line utility (lazbuild). Is necessary to automate the assembly of the project

dbannon

  • Hero Member
  • *****
  • Posts: 2778
    • tomboy-ng, a rewrite of the classic Tomboy
Re: cross compilation by Linux
« Reply #5 on: October 16, 2020, 10:42:18 am »
OK, so only issue was transferring between ? Too easy !  Let us know if you need more specific help.

Its pretty easy to setup cross compilers on Linux, see the wiki.  You could easily setup scripts that build you 32bit and 64bit Linux and Windows binaries. So examples in my github project.

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

PascalDragon

  • Hero Member
  • *****
  • Posts: 5444
  • Compiler Developer
Re: cross compilation by Linux
« Reply #6 on: October 17, 2020, 12:31:32 pm »
I think I need an option
- source code transfer to Linux
- build project
- transfer exe back to Windows

Do you use Windows 10? If so it might be interesting to set up Windows Subsystem for Linux which allows you to run Linux applications on Windows. I use that regulary to compile the compiler for Linux (even for different architectures than x86_64).

anyone

  • Guest
Re: cross compilation by Linux
« Reply #7 on: October 17, 2020, 04:34:43 pm »
Sorry everyone, I have similar question also. (I hope you don't mind @mikutu)

I also want to cross-compile for Linux for a hobby project (you can click that under my Profile). Currently I only feature Windows 32-bit download in my homepage.

@PascalDragon, what is a Windows subsystem? Do you mean VM like VirtualBox?

Then, what download title should I put? Linux (32 / 64-bit) or Ubuntu, Debian....?  %)

Can someone advise what Linux distro to install on my VM to test the Linux cross-compiled program?



Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: cross compilation by Linux
« Reply #8 on: October 17, 2020, 07:46:59 pm »
The advantage and the reason I use Ubuntu is it has large user base. If I have problem with it, I can get more answers searching the web. I use Ubuntu Mate, it is lightweight but still looking good. Some years ago, Ubuntu and its variants have issues with Lazarus installation. So far, it seems the problems have gone.

Which distro is the best for you? You can do some research here:
https://forum.lazarus.freepascal.org/index.php/topic,46434.msg330865.html#msg330865

Also, maybe you will be interested to know and use fpcupdeluxe:
https://wiki.lazarus.freepascal.org/fpcupdeluxe

Lulu

  • Full Member
  • ***
  • Posts: 226
Re: cross compilation by Linux
« Reply #9 on: October 17, 2020, 07:57:09 pm »
Sometime, I use Ubuntu Mate 18.4 under VirtualBox to test Linux cross compiled programs from Windows 10. I use Ubuntu because... Handoko use it !  :D
wishing you a nice life

dbannon

  • Hero Member
  • *****
  • Posts: 2778
    • tomboy-ng, a rewrite of the classic Tomboy
Re: cross compilation by Linux
« Reply #10 on: October 18, 2020, 12:22:45 am »

Then, what download title should I put? Linux (32 / 64-bit) or Ubuntu, Debian....?  %)


Once you have made a linux 32bit and 64bit binary you have something that will run on just about every Linux system around (provided that you resolve dependencies).  But if you want to then package those binaries to allow end users to install easily (and generally resolve dependencies at the same time) you have to address packaging. That means making at least debs and rpms, that will cover, perhaps 80% of users. Not hard but fiddly ...

You may want to look at snap and flatpak too....

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: cross compilation by Linux
« Reply #11 on: October 18, 2020, 07:47:23 am »
Install QEMU or other VM on your computer, install Linux on it and use network folder to share your source code. If you have processor, that supports virtualization, then you can use hardware VM acceleration, so your Linux will run with almost the same performance, as your main system. For example I use HAXM. But if you have Linux installed on real machine, you can always use SSH X forwarding or VNC to control it from Windows machine. For example: install Cygwin and use XLaunch utility to run Linux programs from your windows computer. Including whole desktop, if you need. As for VNC, I personally like mRemoteNG, as it has both Super Putty for SSH tunneling and VNC client, integrated in one single application. Only problem - while VNC supports UTF-8 for displaying characters, it doesn't support it for keyboard input. SSH X forwarding is better in this case.
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

PascalDragon

  • Hero Member
  • *****
  • Posts: 5444
  • Compiler Developer
Re: cross compilation by Linux
« Reply #12 on: October 18, 2020, 12:01:41 pm »
@PascalDragon, what is a Windows subsystem? Do you mean VM like VirtualBox?

No, not really (at least not for WSL1). WSL1 is indeed ELF binaries running directly on top of the NT kernel or more precisely a translation later that intercepts Linux syscalls and translates them to appropriate Windows functionality. Windows NT had these capabilities since its inception where it was possible to run OS/2 console applications in Windows as well or later the POSIX subsystem which (in Windows XP) became Windows Service for Unix applications which required you to compile applications from source. Though that was dropped with Windows 8 before it reemerged again as a completely renewed Windows Subsystem for Linux which allows to run precompiled Linux binaries (e.g. one can use the existing Debian packages if one installs a Debian based distribution).

With WSL2 this was muddled a bit, cause there it is not a translation layer, but indeed a full blown Linux kernel running inside a slim Hyper-V virtual machine, but nevertheless much more transparently integrated into Windows than a normal VM. E.g. one uses the normal console window to interact with the Linux and one can transparently access Windows files from the Linux and vice versa.

See also here.

dbannon

  • Hero Member
  • *****
  • Posts: 2778
    • tomboy-ng, a rewrite of the classic Tomboy
Re: cross compilation by Linux
« Reply #13 on: October 18, 2020, 12:52:28 pm »
....
.... Windows Subsystem for Linux which allows to run precompiled Linux binaries (e.g. one can use the existing Debian packages if one installs a Debian based distribution).

With WSL2 .... a full blown Linux kernel running inside a slim Hyper-V virtual machine, ....

So, WSL for linux required you to install a Linux OS but WSL2 does not ?

While it sounds quite impressive, would such a artificial environment really be suitable for a Windows user to test that their application actually runs as expected on Linux ?  I mean that I find problems between different versions of linux, more driven by the particular desktop than anything else. 

Personally, I would recommend a VM (such as VirtualBox as Lulu and Anyone mentioned).  I would test against at least Ubuntu and RedHats's Fedora. And with several Desktops, Gnome is the default for both but you need also test against KDE/Plasma and, perhaps Mate to cover a reasonable range.  Maybe add Debian and its default XFCe. Thats a fair bit of diskspace tied up and a fair bit of network bandwidth used to initially install and maintain but I have found it necessary.

And don't forget that distros change over time. For example, Ubuntu 16.04 is still a supported distribution, try and get a Lazarus Qt5 app running on it. And for reasons no one understands, Ubuntu left out important GTK2 components from U19.04. RedHat's Gnome desktop has refused to display the System Tray icon for four or five releases now. Sigh ....

I test my app against the ones mentioned and a few more at every release of tomboy-ng, tedious but necessary !

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

PascalDragon

  • Hero Member
  • *****
  • Posts: 5444
  • Compiler Developer
Re: cross compilation by Linux
« Reply #14 on: October 18, 2020, 01:23:45 pm »
So, WSL for linux required you to install a Linux OS but WSL2 does not ?

Both require a Linux distribution of your choice to work. WSL1 only provides the translation interface and WSL2 only the kernel. The userspace is totally up to you.

While it sounds quite impressive, would such a artificial environment really be suitable for a Windows user to test that their application actually runs as expected on Linux ?  I mean that I find problems between different versions of linux, more driven by the particular desktop than anything else.

For GUI applications it's less suited (though you can of course use X applications if you install a X server on Windows and in the near future WSL2 will support Wayland), but for example for compile tests and testing command line applications (or services) it works very nice. For compiler development for example it's a real great help.

 

TinyPortal © 2005-2018