This guide to cross compiling with the mseide-msegui software was deveoped on an amd 64 bit Debian Squeeze computer. If you are on a different distribution and / or architecture you probably will have to alter some things for your specific setup.

Please read this entire document before you begin the cross compile setup.

I will assume you have an existing mseide-msegui environment and that is why you are following this guied.

Setup your 64 bit system for 32 bit compiles. If you aare using a distribution other that Debian Jessie you will most likely have to change the package names.
          sudo dpkg --add-architecture i386
          sudo aptitude update
          sudo aptitude -y install build-essential gcc-multilib.

The next steps will install both a 64 bit and 32 bit version of the free pascal compiler. I recommend that you uninstall / purge your existing free pascal compiler first. I did not do this and had to backup during the process and start over.

I followed the cross comile setup guide at this website link. I will not repeat what it says, but I will note what I had to change to make the setup work.

From the setup guide:

Step 1: "Building" cross linker and assembler:
No changes.

Step 2: Downloading Free Pascal
I downloaded the install tar files from the Free Pascal website (www.freepascal.org). Select The Downlaod link from the Right side of the screen.

For the 64 bit version I then selected the Binaries AMD64/x86_64 Linux link (for my computer setup). I then selected the Austria mirror and then selected the Everything in one big package link for the 64 bit fpc-2.6.0.x86_64-linux.tar file.

For the 32 bit version I selected the Binaries Intel/i386 Linux link. I used the Austria mirror and then selected the Everything in one big package link for the 32 bit fpc-2.6.0.i386-linux.tar file.

For the source I selected the Source download sites link and then seledted the Austria mirror. I then selected the fpcbuild-2.6.0.zip link. Make sure you get the fpcbuild package and not the source package.

Step 3: Installing Free Pascal in your home folder.
I installed the compilers into my home directory as recommended during the install:. My fpc location was then /home/patrick/fpc-2.6.0/i386 and /home/patrick/fpc-2.6.0/x86_64.

Change the $FPVER to your downloaded fpc version number, 2.6.0 in my case.
After the tar -xf fpc-2.6.0.i386-linux.tar I did a cd into the expanded fpc directory and then did the ./install.sh. When it prompts for the install location be sure to enter your desired install location. Repeat the process for the 64 bit version. Make sure you keep the i386 and x86_64 versions in separate folders. Do it in this order, 32 bit install then 64 bit install.

Update your .bashrc file as indicated and logout / login to insure the $PATH is set. I did not do that the first time around and had to logout / login during problems in step 4.

Step 4: Compiling Free Pascal for Linux 64bit and 32bit
When running the su -c command I needed the full path for the compiler, ie: FPC=ppcx64 became FPC=/home/patrick/fpc-2.6.0/x86-64/bin/ppcx64. I will assume that su did not get my $PATH environment variable. I could have added it to the root .bashrc file but did not think of that until after I was all done. That may work for you if you want to try it.

Step 5: Compiling the compiler, RTL and packages for Win32
Same problem here for the su -c command, same solution.

Step 6: Compiling Win64 RTL and packages
Same problem here for the su -c command, same solution.

For the packages I had an additional problem where the error message said "../compiler/ppc not found", but when I looked in the fpcbuild/fpcsrc/compiler folder it was there. This stumped me for a while. I eventually renamed the ppc program to ppc.bak and reran the "make clean" / "make install" commands for the packages. This time it ran. As there are multiple ppc? programs in the fpcsrc/compiler folder I assume that something was not compatible between the ppc program and my system. When I renamed the program the make script selected a different ppc? program and it worked. You may or may not have this problem with a different distribution.

Step 7: Cleaning up.
In addition I did the following as root:
updatedb
locate fpc.cfg
Rename / delete any exisssting fpc.cfg files.

Step 8: Creating a configuration file.
After the configuration file is created run the following command:
fpc -vt nothing.pas and then review the output.

Conclusion.
At this point the cross compile environment it set up and you should be able to compile the hello.pas program as shown.

Now on to the mseide-msegui environment.

I copied the kernel/i386-linux and kernel/i386-win32 to kernel/x86_64-linux and kernel/x86_64-win64. The kernel/x86_64-linux source will work as is. The kernel/x86_64-win64 source will have to be updated for 64 bit processing before you will be able to successfully compile 64 bit windows programs. For now, that remains to be done.

Install the multiarch packages for your distribution: ia32-libs, ia32-libs-dev, gcc-multilib for Debian.

Update your /etc/fpc.cfg
The linker has the /usr/lib hard coded in its library list. So I was getting link errors on 32 bit linux programs. After a lot of searching I eventually found a posting on the free pascal bug forum as to what was happening and why. Unfortunately it was late at night and I did not bookmark the post. The fix is to update the fpc.cfg file with the following

# compile for linux 32 bit
#ifdef cpui386
#ifdef linux
# prevent searching the default library directories
-Xd
# add the 32 bit-specific library directories
-Fl/usr/lib32;/usr/lib/gcc/x86_64-linux-gnu/4.4/32
# -Fl/other/32bit/directories
#endif
#endif

Select an mseide project to work with. Create 4 subfolders in your projects folder for the 4 different compile versions, name them i386-linux, i386-win32, x86_64-linux and x86_64-win64. The 4 subfolders will keep the compiled programs separate, otherwise you will replace your just compiled 64 bit linux or windows programs with the 32 bit version when you switch macros.

Start the mseide-msegui program.

select Project -> Options.
Select the Make tab.
Update the make targetfile to: ${TARGET}/${PROJECTNAME}${EXEEXT}
Add a makeoption $T{OS} and check it for make and build (and options 1 thru 4 if desired)

Click on the Make Directories
Verify the make directory for the kernel is ${MSELIBDIR}kernel/${TARGET}/
Add a make directory ${TARGET}/ check boxes for mb1234ui

Click on the Macro tab and add 4 macros for linux 64 / 32 bit and windows 64 / 32 bit compiles.
Name them Linux 64, Linux 32, Windows 64, Windows 32 or something meaningful to you.

Add thw following entries for Name and Value
Name Value
TARGET x86_64-linux
OS linux
EXEEXT
COMPILER ppcx64

TARGET i386-linux
OS linux
EXEEXT
COMPILER ppc386

TARGET x86_64-win64
OS win64
EXEEXT .exe
COMPILER ppcx64

TARGET i386-win32
OS win32
EXEEXT .exe
COMPILER ppc386

Activate / select each macro in turn and click on Project -> Make. You should get 3 clean compiles for the 64 and 32 bit linux macros and the 32 bit windows macro. The 64 bit windows shoudl fail (until we get updated kernel/x86_64-win64 source code).

If you get a link error for a 32 bit module not found, then as root do
updatedb
locate "the missing file name"
Add the file to the /etc/fpc.cfg from the previous config step "Update your /etc/fpc.cfg".

That should do it.

Please report any problems you have while trying to follow this guide.