Recent

Author Topic: Question about cross-compiling win32 vs. win64  (Read 1155 times)

QuinnMartin

  • New Member
  • *
  • Posts: 27
Question about cross-compiling win32 vs. win64
« on: August 15, 2022, 07:01:09 pm »
Sorry this may be a dumb question, but is it easy to use the very same Lazarus installation and source code to compile both a Windows x32 and x64 executable?  Or does this require digging into configuration settings or FPC libraries and modifying stuff?  I did a cursory search and keep finding a lot of posts from 2010-2015 which may not be relevant now.

I would like to offer my users both a x32 and x64 executable, but will just stick with one if the process is complicated.

tetrastes

  • Sr. Member
  • ****
  • Posts: 473
Re: Question about cross-compiling win32 vs. win64
« Reply #1 on: August 15, 2022, 08:01:41 pm »
Yes, it is easy.

QuinnMartin

  • New Member
  • *
  • Posts: 27
Re: Question about cross-compiling win32 vs. win64
« Reply #2 on: August 15, 2022, 08:19:04 pm »
Can I build x64 executables from 32-bit Lazarus, or do I need 64-bit Lazarus to do both?

Handoko

  • Hero Member
  • *****
  • Posts: 5129
  • My goal: build my own game engine using Lazarus
Re: Question about cross-compiling win32 vs. win64
« Reply #3 on: August 15, 2022, 08:23:58 pm »
I use Linux, not much I can say for Windows. But this maybe can help you:
https://wiki.lazarus.freepascal.org/Cross_compiling#From_win32_to_win64

mas steindorff

  • Hero Member
  • *****
  • Posts: 532
Re: Question about cross-compiling win32 vs. win64
« Reply #4 on: August 15, 2022, 09:16:18 pm »
also simple in the IDE "options for project" (the gear icon on the 2nd line next to the green play button), you can setup different "build modes".  I tend to have 4, two for 32 bit (debug and release) and two more for 64 bit.  Once you have your build modes defined, go to the "config and target" option and set your target for each. win64 or win32 as an example.

 
windows 10 &11, Ubuntu 21+ - fpc 3.0.4, IDE 2.0 general releases

tetrastes

  • Sr. Member
  • ****
  • Posts: 473
Re: Question about cross-compiling win32 vs. win64
« Reply #5 on: August 15, 2022, 10:00:19 pm »

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Question about cross-compiling win32 vs. win64
« Reply #6 on: August 16, 2022, 12:57:58 pm »
Sorry this may be a dumb question, but is it easy to use the very same Lazarus installation and source code to compile both a Windows x32 and x64 executable?  Or does this require digging into configuration settings or FPC libraries and modifying stuff?

It essentially boils down to installing the corresponding addon for your IDE (if you have the i386-win32 one you need to install the x86_64-win64 addon and vice versa). After that you only need to set the correct target in your project settings.

QuinnMartin

  • New Member
  • *
  • Posts: 27
Re: Question about cross-compiling win32 vs. win64
« Reply #7 on: August 17, 2022, 03:21:15 am »
Thank you very much, I think it's starting to make a little more sense now.

The one thing I can't figure out is compiling a Linux executable in a Win32 environment.  Is this realistic, or should all Linux executables be built under Lazarus in Linux?  I'm trying to avoid an overly complicated setup, and some of the instructions I found were over my head.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Question about cross-compiling win32 vs. win64
« Reply #8 on: August 17, 2022, 09:10:39 am »
You need to build FPC yourself in that case (so that you have the RTL and FCL available). For that you need the correct binutils. Also you need to have all required library available on your build system, because that's how linking on *nix systems work (for e.g. the Windows targets the libraries aren't required). It might be that fpcupdeluxe can help you here, but I can't say for sure, because I don't use it.
In the end it might be best to compile in a Linux distribution or - if you have Windows 10 - by using WSL.
In how far your application is then portable across distributions depends upon what C library the distribution you pick for compilation has. E.g. current Debian and Ubuntu releases use 2.31 which also allows your application to run on systems with a newer C library. But if you compile against e.g. 2.35 (used in current ArchLinux) then it won't be able to run on a system with a 2.31 one (which are still quite common).

QuinnMartin

  • New Member
  • *
  • Posts: 27
Re: Question about cross-compiling win32 vs. win64
« Reply #9 on: August 17, 2022, 04:51:59 pm »
OK, I appreciate it.. that points me in the right direction.  It sounds like I should just write it in Lazarus under Windows (where I do most of my work) and port the project over to a separate Linux Lazarus installation later and compile it there.

 

TinyPortal © 2005-2018