Cross-compile (Win32 + win64) plugin in Lazarus

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: white, sheep, Hacker, Stefan2

Post Reply
Enyby
Junior Member
Junior Member
Posts: 27
Joined: 2018-08-12, 16:02 UTC

Cross-compile (Win32 + win64) plugin in Lazarus

Post by *Enyby »

Task: Make a simultaneous compilation of the plugin in Lazarus.
To make it build immediately for 32-bit and for 64-bit.
I will consider the example of the content of the WDX plugin.

The first solution is dirty and fast.

In the properties of the project specify the desired architecture and target OS. Then click the "Show options" button at the bottom of the dialog.

There will be something like:

Code: Select all

-Twin32 -Pi386 -MObjFPC -Scghi -WR -O1 -g -gl -l -vewnhibq -Filib\i386-win32 -Fu. -FUlib\i386-win32
You copy this text. Go to the tab "compiler commands". There you insert this text into the compiler command that is executed before compilation.
Before this text write

Code: Select all

$(CompPath)
After it add

Code: Select all

$ProjFile()
Do not forget to separate them with spaces.

Put a tick on the FPC.

After that, install the target OS and architecture, in the properties of the project, for the second purpose of the assembly.

In the project source, add the following code, so that there is a different extension for different architectures:

Code: Select all

{$ifdef Win32}
	{$EXTENSION 'wdx'}
{$else}
	{$EXTENSION 'wdx64'}
{$endif}   
This is enough for everything to work if you do not change the compilation parameters. If you change them, do not forget to change them in this text.
Enyby
Junior Member
Junior Member
Posts: 27
Joined: 2018-08-12, 16:02 UTC

Re: Cross-compile (Win32 + win64) plugin in Lazarus

Post by *Enyby »

The second solution is more correct, but it requires third-party solutions (php for example).

I did not implement it, because I did not have such a need, therefore I will describe only the conceptual form.

You replace the compiler command with something like:

Code: Select all

php $(ProjPath)\compiler.php $(CompPath)
php must be in system PATH, or specify absolute path for it.

As a result, instead of a compiler, a php script is launched that takes all the necessary parameters.

In this php script, you take all the parameters, and replace the target OS ("-Twin32" or "-Twin64") and architecture ("-Pi386" or "-Px86_64") in them with all the necessary options (do not forget about dirs for "-Fi" and "-FU").
After that, call the compiler few times with all the necessary compilation options, giving it its output.

This solution allows you to transparently transfer all compilation options, even if you change them through settings.

Strictly speaking, it is not necessary to write an auxiliary utility in php. You can do it on anything. I know php, so I will write it in half an hour in php.
If you know something else, you can write a console application / script on it.
For example, on the same Lazarus, make a console wrapper application to run the compiler.
User avatar
jaco777
Junior Member
Junior Member
Posts: 19
Joined: 2015-03-23, 21:56 UTC
Location: Poland
Contact:

Re: Cross-compile (Win32 + win64) plugin in Lazarus

Post by *jaco777 »

Thanks for the instruction.

I did it like here: https://forum.lazarus.freepascal.org/index.php/topic,41142.0.html

I added new Release_32 and Release_64, and configured them in Project> Options> Compiler Options> Config and Target.
No need change string Commands in Compiler Command, no need check FPC - and work.

I use Your declaration:

Code: Select all

{$ifdef Win32}
	{$EXTENSION 'wfx'}
{$else}
	{$EXTENSION 'wfx64'}
{$endif}
Post Reply