How to use the GCC Compiler

GNU C

Updated: 17/07/2023

The GCC compiler (Gnu C Compiler) is written by the GCC team of the Free Software Foundation. The lastest version of GCC is 4.6. The last version of GCC for AmigaOS 3.x is 2.7.x, and the current version for Amiga OS 4.x is 4.2.4

Contents of GCC Package:

GCC for Amiga OS 3.x is available on Aminet,.
GCC for Amiga OS 4.x is available from the SDK.
GCC for AROS comes with the ISO for Icaros and other distros.
The GCC is available in multiple parts depending on the operating system.

Installation

Download the GCC packages from Aminet.

gcc270-base.lha
gcc270-c.lha
gcc270-c020.lha
gcc270-cp.lha
gcc270-cp020.lha
gcc270-doc.lha
gcc270-inclib.lha
gcc270-objc.lha
gcc270-objc020.lha
gcc270-readme.lha
gcc270-src.lha (optional)

Updates:
gcc-bin.lha = GCC v2.7.2.1 update
gcc-src.lha = GCC v2.7.2.1 source update

gcc-faq_0.7.lha - Useful frequently asked questions about GCC.

Start with the base install and follow with installation C/C++ (cp) packages and the remaining parts.
You will need to set your shell stack to at least 50k e.g. stack 50000 to use gcc.

Directories and folders

An GCC installation contains a number of directories and assigns needed for it to run.

gcc - main directory (or sdk for Amiga OS 4 gcc)
include - Header files for gcc
documentation - developer, library, autodocs
bin - gcc program files

GCC Main Programs

gcc - Main compiler program (C programs)
as - Assembler
cpp - C Pre-processor
g++ - C++ compiler
gas - GNU Assembler
gasp - GNU assembler preprocessor
gdb - GNU debugger
gperf - GN perfect hash function generator
make - Compile and build GNC C projects

How to create an GCC Project

1. Open a Shell and make sure stack is set high enough e.g. stack 50000.

2. Create a new folder for your directory e.g. makedir Work:MyProject and cd to it.

3. Use Ed or your favourite editor (notepad) to create your source code e.g. notepad program.c

4 To compile a single program, enter gcc program.c -o program or g++ program.c -o program for C++ programs.

If you do not specify the -o option then the resulting program will be called a.out. If you forget the -o option, you can rename the a.out file to a more meaningful name. You can use the -g option to include debug information which can be utilised by gdb debuffer tool.

To include the OS library functions and recognise Interface names, add the -lauto option at the end of the compiler command.

You can specify multiple options with vc (see the vbcc documentation on what the options are). If there are too many options

then use the -cmd option and use a file with all the options specified in it. GCC will compile using the ixemul.library, if you want to avoid using it, then use the -noixemul

option, and link with libnix instead to keep programs small and more Amiga-friendly.

5. To test your program type the program name e.g. program.

How to use make and makefiles

You can create a make file for each project. The all section describes the resulting program name, the next lines describe how to create the program and the object. The clean section allows you to run make clean to recompile from scratch if necessary. the command line (gcc) on next line preceeded by a TAB character, or use a semi-colon and have the command on the same line as the rule. Just type make to compile your project.If you need to debug, add the -g option before -lauto, then you can run gdb myprogram to run and debug the program safely.
E.g.

all: myprogram
myprogram: myprogram.o   ; gcc -o myprogram myprogram.o -lauto
myprogram.o: myprogram.c ; gcc -c myprogram.c
clean: ; delete myprogram.o myprogram

More information on makefiles can be found on the GCC and Make page.

Converting programs from AmigaOS 3 to AmigaOS 4

1. In AmigaOS 4, library calls are prefixed with interface names such as IExec, IDOS, IIntuition etc. If there a lot of calls, that may be too much work, so instead, you can enable the __USE_INLINE__ definition to tell compiler to use macros for functions pre-fixed you in the inline/ folder enabled via the proto headers.
2. Some functions are deprecated (no longer used) in AmigaOS 4, so to ease conversion, you can use __amigaos4__ definitions to differenciate code for AmigaOS 4 from AmigaOS 3 functions to call use different function calls depending on the OS.
3. Memory functions have changed a lot in AmigaOS 4, so AllocMem(), AllocVec and CreatePool() functions are deprecated in favour of newer functions.
4. MUI programs should be updated for MUI 5.0, and use of INLINE function calls would help a lot. Make sure plenty of stack memory is allocated.

Converting programs from AmigaOS 3 to AROS

AROS, such as Icaros, comes with a GCC v4 compiler, and most AmigaOS 3 programs can be easily recompiled to run on AROS (68k or x86) systems. AROS supports most Workbench programs using Intuition, Gadtools, Bgui and MUI 3 (or later with some modifications) which is known as Zune on AROS. Programs written for Classact or Reaction will not compile on ARO, convert them to use Zune (MUI) to work on AROS.

 

Back to Contents