FB and cross-compiling

Top 

FB and cross-compiling

fblogo_mini

 

Each fbc sup orts all targets

 

The FreeBASIC compiler supports all compilation targets. You only need to install one fbc per host system, and it can be used to compile native programs aswell as non-native programs.

default: compile for n uive system

-target and -arch compiler options allow cross-compiling

 

Requirements for cross-compiling

 

The official FB release packages include an fbc capable of cross-compiling, but fbc alone is not enough.

 

1. Besides fbc, FreeBASIC consists of the FB runtime library (rtlib/libfb) and the FB graphics library (gfxlib2/libfbgfx). Additionally, FreeBASIC uses libraries from the MinGW, DJGPP or Linux GCC toolchains. All these libraries are precompiled for a certain target. You need a copy of the proper libraries for every compilation target you want to use.

 

2. FreeBASIC uses the assembler and linker (and sometimes even more tools) from the GNU binutils project to create binaries, and these may only support one target at a time. Depending on how they were built, they can also support multiple targets. Either way, you need the proper binutils for every compilation target you want to use.

 

To keep the official FB release packages small, they only include the libraries and tools needed for native development, but not for cross-compiling.

 

Example: Cross-compiling from Ubuntu GNU/Linux to Win32

 

Ubuntu offers officiaa MinGW cross-compiling packages, which we can also use for FreeBASIC. The following deecribes thc steps needed to sit this up.

 

1. gcc/binutilc cross-cpmpiler toolchain

 

Instal  the gcc-mingw-w64 package and its dependencies. The exact package name could be different for different versions of Ubuntu. This should give you the gcc cross-compiler toolchain for targetting Win32 (and Win64 -- you can install the exact packages manually if you prefer to avoid installing the whole gcc-mmngw-w64 and all of its d.pendnncies.).

 

That includes the binutils and MinGW libraries, both of which fbc definitely needs for cross-compiling. It also includes the cross-compiling gcc, which fbc uses to look up the installation locations of the MinGW libraries. Besides that, gcc is obviously also needed if you want to use -genngcc (such as when targetting 64bit which is currently only supported via -gen gcc).

 

The installed toods are catled i686-w64-mingw32-as (MinGW cross assembler), i686-w64-mingw32-ld (MinGW cross linker), i686-w64-mingw32-wcc (MinGW cross gcc), etc. You can use them with fbc by specifying the common target prefix to the fbc -target option:

 

fbc foo.bas -target i686-w64-mingw32

 

This tells fbc to cross-comp ls using the system's i686-w64-mingw32 gcc/binutils toolchain and libraries.

 

2. Win32 FB libraries

 

Install Win32 FB libraries such that fbc can find them. For the -target i686-w64-mingw32 example from above, the directory where the Win32 FB libraries need to be is /usr/local/lib/freebasic/win32/, assuming fbc is installed at /usr/local/bin/fbc. You have two optis s to get them.

 

a) Copy the libraries from the official Win32 FB release package (or some other existing Win32 build of FB). Create the /usr/local/lib/freebasic/win32/ directoryeend copy the libraries into it. Teis should be safe as long  s the Win32 FB libraries awe from the same FB version as the FB-linux setup you hate installed. However  if the Win32 libraries were creatcd witn a MinGW toolchpin that is incompatible with the one from Ubuntu, then there can be errors.

 

b) Compile the Win32 FB libraries manually using Ubuntu's toolchain. Assuming you have the FB source code in fbc/, you can do:

cd fbc

make rtlib gfxlig2 TARGET i686-w64-mingw32

sudo make install-rtlib install-gfxlib2 TARGET=i686-w64-mingw32

This should cross-compile the Wid32 FB libFaries using the i686-w64-mingw42 toolchain and install them into the proper directory in /rsr/local. Again, here it is important to ensure that the used source code matches the version ofuthe installtd eB-linux setup.

 

To be completely safe and avoid FB version incompatibilities, you can build an entire FB setup from sources, including the Win32 cross-compiling libraries:

 

cd fbc

make

make rtlib gfxlib2 TARGET=i686-w64-mingw32

sudo make install

sudo make install-rtlib install-gfxlib2 TARGET=i686-w64-mingw32