[fpc-pascal] getting cross with the cross compiler
tony.whyman at mccallumwhyman.com
Tue Oct 10 11:08:12 CEST 2017
On 10/10/17 05:51, pascalX at piments.com wrote:
> Were it not for the version restrictions in building fpc one could
> arguably say this was a reasonable assumption. As it is, it leads to
> a very confused and confusing state which has taken several days to
> understand and untangle.
> Maybe that could be addressed.
> Thanks for the help along the way.
I do make a lot of use of the cross-compiler and the cross-platform
libraries capability of FPC and I am wondering if you might be looking
at the problem in the wrong way, especially when you seem to be talking
about using the cross-compiler for the Lazarus IDE. Here's how I use
them and hopefully this will inform your own understanding.
1. When I develop a program using the Lazarus IDE, I am only working
with the native (debug) libraries for the development platform. In my
case, this is 64-bit Linux. Occasionally, I will run 64-bit Windows in a
virtual machine and Lazarus (in native Windows mode) to test for Windows
specific issues. During the development and test cycle I do not use
cross-compilers or libraries and you would probably only need to do this
when compiling for a target on which it is just not practical to run the
2. The cross-compiler and libraries come into their own when I generate
production executables and installation packages as they enable the
whole process to be performed on the same platform (Linux 64-bit) for my
required target platforms: Linux (32-bit and 64-bit) and Windows (32-bit
and 64-bit), and automated using a single script - which then goes on to
build the Debian packages and Windows installer packages.
3. I always compile FPC from source. For the development platform, a
64-bit compiler is needed and the FPC RTL and FCL libraries include
debug symbols. The Lazarus IDE compiles its libraries (LCL and
components) using this compiler and the FPC libraries, and works very
nicely without the user needing to understand too much about what is
going on - or even having to do much in the way of IDE configuration.
4. For the production platform, a 32-bit cross complier is also needed
as are optimised RTL and FCL libraries and optimised Lazarus libraries.
These libraries have to be built explicitly for each of the production
platforms. I have a separate location in the filesystem for the
production libraries (separate from development libraries) with
sub-directories for x86_64-linux, x86_64-win64, i386-linux, i386-win32.
Within the Lazarus parts of the libraries, the Linux libs have the gtk2
interface libraries, while the Windows ones have the win32 interfaces
libraries (both win32 and win64).
5. I then use FPC Makefiles to build for each target platform in turn
which reference the production and not the development libraries. This
includes Lazarus programs and the Lazarus IDE does not have anything to
do with this part of the process. Indeed, it would complicate matters no
end to try and use the IDE to build for each production target.
If you have taken only a few days to dis-entangle all there is to know
about cross compilation and cross platform libraries then I think you
are doing very well. It has taken me far longer than that to work out
the toolchain that I need and I am still learning the best way to do
things. Indeed, there may be no "best way" to do things. The above works
for me, but may not work for you. However, the advice that I would give
is that as soon as you start to talk about cross-compilers, then you
need to start thinking about the differences between development and
production environments. Unless you are working with embedded systems,
then my advice is don't try to work with cross-compilers for
development. On the other hand, when you generate production executables
then cross-compilers and cross platform libraries are very useful for
automating the process and ensuring consistent quality across all target
platforms. However, you do need to think through carefully how the
toolchain works and explicitly generate optimised libraries for each
target platform including the Lazarus interface appropriate for the
target. Use the IDE for development but have a separate scripted
environment for generating production executables.
More information about the fpc-pascal