SDCC Compiler User Guide

SDCC Compiler User Guide

Chapter 2

Installing SDCC

For most users it is sufficient to skip to either section


or section


. More detailled instructions follow



Configure Options

The install paths, search paths and other options are defined when running ’configure’. The defaults can be overridden by:

--prefix see table below

--exec_prefix see table below

--bindir see table below

--datadir see table below docdir environment variable, see table below include_dir_suffix environment variable, see table below lib_dir_suffix environment variable, see table below sdccconf_h_dir_separator environment variable, either / or \\ makes sense here. This character will only be used in sdccconf.h; don’t forget it’s a C-header, therefore a double-backslash is needed there.

--disable-mcs51-port Excludes the Intel mcs51 port

--disable-gbz80-port Excludes the Gameboy gbz80 port

--disable-z80-port Excludes the z80 port

--disable-avr-port Excludes the AVR port

--disable-ds390-port Excludes the DS390 port

--disable-hc08-port Excludes the HC08 port

--disable-pic-port Excludes the PIC port

--disable-xa51-port Excludes the XA51 port

--disable-ucsim Disables configuring and building of ucsim

--disable-device-lib-build Disables automatically building device libraries

--disable-packihx Disables building packihx

--enable-libgc Use the Bohem memory allocator. Lower runtime footprint.



Furthermore the environment variables CC, CFLAGS, ... the tools and their arguments can be influenced. Please see ‘configure --help‘ and the man/info pages of ‘configure‘ for details.

The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB,

STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,

SDCC_LIB_NAME are defined by ‘configure‘ too. At the moment it’s not possible to change the default settings

(it was simply never required).

These configure options are compiled into the binaries, and can only be changed by rerunning ’configure’ and recompiling SDCC. The configure options are written in italics to distinguish them from run time environment variables (see section search paths).

The settings for ”Win32 builds” are used by the SDCC team to build the official Win32 binaries.


SDCC team uses Mingw32 to build the official Windows binaries, because it’s

1. open source,

2. a gcc compiler and last but not least

3. the binaries can be built by cross compiling on Sourceforge’s compile farm.

See the examples, how to pass the Win32 settings to ’configure’. The other Win32 builds using Borland, VC or whatever don’t use ’configure’, but a header file sdcc_vc_in.h is the same as sdccconf.h built by ’configure’ for


These defaults are:









default Win32 builds

/usr/local \sdcc




$DATADIR/sdcc/doc sdcc/include sdcc/lib


$DATADIR\doc include lib

’configure’ also computes relative paths. This is needed for full relocatability of a binary package and to complete search paths (see section search paths below):

Variable (computed) default



../share bin



Win32 builds





./configure --prefix=”/usr/bin” --datadir=”/usr/share”

./configure --disable-avr-port --disable-xa51-port

To cross compile on linux for Mingw32 (see also ’sdcc/support/scripts/sdcc_mingw32’):

./configure \

CC=”i586-mingw32msvc-gcc” CXX=”i586-mingw32msvc-g++” \

RANLIB=”i586-mingw32msvc-ranlib” \

STRIP=”i586-mingw32msvc-strip” \

--prefix=”/sdcc” \



--datadir=”/sdcc” \ docdir=”/sdcc/doc” \ include_dir_suffix=”include” \ lib_dir_suffix=”lib” \ sdccconf_h_dir_separator=”\\\\” \



--host=i586-mingw32msvc --build=unknown-unknown-linux-gnu

To ”cross”compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32):

./configure -C \

CFLAGS=”-mno-cygwin -O2” \

LDFLAGS=”-mno-cygwin” \

--prefix=”/sdcc” \

--datadir=”/sdcc” \ docdir=”/sdcc/doc” \ include_dir_suffix=”include” \ lib_dir_suffix=”lib” \ sdccconf_h_dir_separator=”\\\\” \


’configure’ is quite slow on Cygwin (at least on windows before Win2000/XP). The option ’--C’ turns on caching, which gives a little bit extra speed. However if options are changed, it can be necessary to delete the config.cache



Install paths


Binary files*

Include files

Library file**


Path Default Win32 builds


/usr/local/bin \sdcc\bin


/usr/local/share/sdcc/include \sdcc\include


/usr/local/share/sdcc/lib \sdcc\lib


/usr/local/share/sdcc/doc \sdcc\doc

*compiler, preprocessor, assembler, and linker

**the model is auto-appended by the compiler, e.g. small, large, z80, ds390 etc

The install paths can still be changed during ‘make install‘ with e.g.: make install prefix=$(HOME)/local/sdcc

Of course this doesn’t change the search paths compiled into the binaries.

Moreover the install path can be changed by defining DESTDIR: make install DESTDIR=$(HOME)/sdcc.rpm/

Please note that DESTDIR must have a trailing slash!


Search Paths

Some search paths or parts of them are determined by configure variables (in italics, see section above). Further search paths are determined by environment variables during runtime.

The paths searched when running the compiler are as follows (the first catch wins):

1. Binary files (preprocessor, assembler and linker)



2. Include files

Search path default Win32 builds


Path of argv[0] (if available)


Path of argv[0]


Path of argv[0]


Search path

--I dir











--I dir


$SDCC_ HOME/ share/sdcc/ include path(argv[0])/


/usr/local/share/sdcc/ include

The option --nostdinc disables the last two search paths.

Win32 builds

--I dir


$SDCC_HOME\include path(argv[0])\..\include

(not on Win32)

3. Library files

With the exception of ”--L dir” the model is auto-appended by the compiler (e.g. small, large, z80, ds390 etc.).

Search path

--L dir












--L dir



$SDCC_HOME/ share/sdcc/ lib/<model> path(argv[0])/


/usr/local/share/sdcc/ lib/<model>

The option --nostdlib disables the last two search paths.

Win32 builds

--L dir







(not on Win32)


Building SDCC


Building SDCC on Linux

1. Download the source package either from the SDCC CVS repository or from the nightly snapshots, it will be named something like sdcc.src.tar.gz


2. Bring up a command line terminal, such as xterm.

3. Unpack the file using a command like:

"tar -xvzf sdcc.src.tar.gz

", this will create a sub-directory called sdcc with all of the sources.

4. Change directory into the main SDCC directory, for example type:

"cd sdcc".

5. Type


". This configures the package for compilation on your system.

6. Type


". All of the source packages will compile, this can take a while.

7. Type

"make install"

as root. This copies the binary executables, the include files, the libraries and the documentation to the install directories. Proceed with section






Building SDCC on OSX 2.x

Follow the instruction for Linux.

On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.

Fortunately there’s also gcc 2.9.x installed, which works fine. This compiler can be selected by running ’configure’ with:

./configure CC=gcc2 CXX=g++2


Cross compiling SDCC on Linux for Windows

With the Mingw32 gcc cross compiler it’s easy to compile SDCC for Win32. See section ’Configure Options’.


Building SDCC on Windows

With the exception of Cygwin the SDCC binaries uCsim and sdcdb can’t be built on Windows. They use Unixsockets, which are not available on Win32.


Building SDCC using Cygwin and Mingw32

For building and installing a Cygwin executable follow the instructions for Linux.

On Cygwin a ”native” Win32-binary can be built, which will not need the Cygwin-DLL. For the necessary

’configure’ options see section ’configure options’ or the script ’sdcc/support/scripts/sdcc_cygwin_mingw32’.

In order to install Cygwin on Windows download setup.exe from


Run it, set the ”default text file type” to ”unix” and download/install at least the following packages. Some packages are selected by default, others will be automatically selected because of dependencies with the manually selected packages. Never deselect these packages!

• flex

• bison

• gcc ; version 3.x is fine, no need to use the old 2.9x

• binutils ; selected with gcc

• make

• rxvt ; a nice console, which makes life much easier under windoze (see below)

• man ; not really needed for building SDCC, but you’ll miss it sooner or later

• less ; not really needed for building SDCC, but you’ll miss it sooner or later

• cvs ; only if you use CVS access

If you want to develop something you’ll need:

• python ; for the regression tests

• gdb ; the gnu debugger, together with the nice GUI ”insight”

• openssh ; to access the CF or commit changes

• autoconf and autoconf-devel ; if you want to fight with ’configure’, don’t use autoconf-stable!

rxvt is a nice console with history. Replace in your cygwin.bat the line bash --login -i


2.4. BUILDING SDCC CHAPTER 2. INSTALLING SDCC with (one line): rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red

-bg black -fg white -geometry 100x65 -e bash --login

Text selected with the mouse is automatically copied to the clipboard, pasting works with shift-insert.

The other good tip is to make sure you have no //c/-style paths anywhere, use /cygdrive/c/ instead. Using // invokes a network lookup which is very slow. If you think ”cygdrive” is too long, you can change it with e.g.

mount -s -u -c /mnt

SDCC sources use the unix line ending LF. Life is much easier, if you store the source tree on a drive which is mounted in binary mode. And use an editor which can handle LF-only line endings. Make sure not to commit files with windows line endings. The tabulator spacing used in the project is 8. Although a tabulator spacing of 8 is a sensible choice for programmers (it’s a power of 2 and allows to display 8/16 bit signed variables without loosing columns) the plan is to move towards using only spaces in the source.


Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)

Download the source package either from the SDCC CVS repository or from the nightly snapshots

, it will be named something like sdcc.src.tgz.

SDCC is distributed with all the projects, workspaces, and files you need to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently doesn’t build under MSVC). The workspace name is ’sdcc.dsw’. Please note that as it is now, all the executables are created in a folder called sdcc\bin_vc. Once built you need to copy the executables from sdcc\bin_vc to sdcc\bin before running SDCC.

WARNING: Visual studio is very picky with line terminations; it expects the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings. When using the CVS repository it’s easiest to configure the cvs client to convert automatically for you. If however you are getting a message such as "This makefile was not generated by Developer Studio etc. etc.” when opening the sdcc.dsw workspace or any of the *.dsp projects, then you need to convert the Unix style line endings to DOS style line endings. To do so you can use the ”unix2dos” utility freely available on the internet. Doug Hawkins reported in the sdcc-user list that this works:

C:\Programming\SDCC> unix2dos sdcc.dsw

C:\Programming\SDCC> for /R %I in (*.dsp) do @unix2dos "%I"

In order to build SDCC with MSVC you need win32 executables of bison.exe, flex.exe, and gawk.exe. One good place to get them is here

Download the file Now you have to install the utilities and setup MSVC so it can locate the required programs. Here there are two alternatives (choose one!):

1. The easy way: a) Extract to your C:\ hard disk PRESERVING the original paths, otherwise bison won’t work.

(If you are using WinZip make certain that ’Use folder names’ is selected) b) In the Visual C++ IDE click Tools, Options, select the Directory tab, in ’Show directories for:’ select ’Executable files’, and in the directories window add a new path: ’C:\user\local\wbin’, click ok.

(As a side effect, you get a bunch of Unix utilities that could be useful, such as diff and patch.)

2. A more compact way:

This one avoids extracting a bunch of files you may not use, but requires some extra work: a) Create a directory were to put the tools needed, or use a directory already present. Say for example ’C:\util’.


2.4. BUILDING SDCC CHAPTER 2. INSTALLING SDCC b) Extract ’bison.exe’, ’bison.hairy’, ’bison.simple’, ’flex.exe’, and gawk.exe to such directory WITHOUT preserving the original paths. (If you are using WinZip make certain that ’Use folder names’ is not selected) c) Rename bison.exe to ’_bison.exe’.

d) Create a batch file ’bison.bat’ in ’C:\util\’ and add these lines: set BISON_SIMPLE=C:\util\bison.simple

set BISON_HAIRY=C:\util\bison.hairy

_bison %1 %2 %3 %4 %5 %6 %7 %8 %9

Steps ’c’ and ’d’ are needed because bison requires by default that the files ’bison.simple’ and ’bison.hairy’ reside in some weird Unix directory, ’/usr/local/share/’ I think. So it is necessary to tell bison where those files are located if they are not in such directory. That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.

e) In the Visual C++ IDE click Tools, Options, select the Directory tab, in ’Show directories for:’ select ’Executable files’, and in the directories window add a new path: ’c:\util’, click ok. Note that you can use any other path instead of ’c:\util’, even the path where the Visual C++ tools are, probably: ’C:\Program

Files\Microsoft Visual Studio\Common\Tools’. So you don’t have to execute step ’e’ :)

That is it. Open ’sdcc.dsw’ in Visual Studio, click ’build all’, when it finishes copy the executables from sdcc\bin_vc to sdcc\bin, and you can compile using SDCC.


Building SDCC Using Borland

1. From the sdcc directory, run the command "make -f Makefile.bcc". This should regenerate all the .exe files in the bin directory except for sdcdb.exe (which currently doesn’t build under Borland C++).

2. If you modify any source files and need to rebuild, be aware that the dependencies may not be correctly calculated. The safest option is to delete all .obj files and run the build again. From a Cygwin BASH prompt, this can easily be done with the command (be sure you are in the sdcc directory):

find . \( -name ’*.obj’ -o -name ’*.lib’ -o -name ’*.rul’ \) -print -exec rm {} \;

or on Windows NT/2000/XP from the command prompt with the command:

del /s *.obj *.lib *.rul

from the sdcc directory.


Windows Install Using a ZIP Package

1. Download the binary zip package from

and unpack it using your favorite unpacking tool (gunzip, WinZip, etc). This should unpack to a group of sub-directories. An example directory structure after unpacking the mingw32 package is: c:\sdcc\bin for the executables, c:\sdcc\include and c:\sdcc\lib for the include and libraries.

2. Adjust your environment variable PATH to include the location of the bin directory or start sdcc using the full path.


Windows Install Using the Setup Program

Download the setup program sdcc-x.y.z-setup.exe for an official release from or a setup program for one of the snapshots

sdcc_yyyymmdd_setup.exe from

and execute it. A windows typical installer will guide you through the installation process.




Building the Documentation

If the necessary tools (LYX, L TEX, L


TEX2HTML) are installed it is as easy as changing into the doc directory and typing


there. You’re invited to make changes and additions to this manual (sdcc/doc/sdccman.lyx).

Using LYX

as editor this is straightforward. Prebuilt documentation in html and pdf format is available from



Reading the Documentation

Currently reading the document in pdf format is recommended, as for unknown reason the hyperlinks are working

there whereas in the html version they are not



You’ll find the pdf version at


A html version should be online at


This documentation is in some aspects different from a commercial documentation:

• It tries to document SDCC for several processor architectures in one document (commercially these probably would be separate documents/products). This document currently matches SDCC for mcs51 and DS390 best and does give too few information about f.e. Z80, PIC14, PIC16 and HC08.

• There are many references pointing away from this documentation. Don’t let this distract you. If there f.e.

was a reference like

together with a statement ”some processors which are targetted by SDCC can be implemented in a f ield programmable gate array” we expect you to have a quick look there and come back. If you read this you are on the right track.

• Some sections attribute more space to problems, restrictions and warnings than to the solution.

• The installation section and the section about the debugger is intimidating.

• There are still lots of typos and there are more different writing styles than pictures.


Testing the SDCC Compiler

The first thing you should do after installing your SDCC compiler is to see if it runs. Type

"sdcc --version"

at the prompt, and the program should run and tell you the version. If it doesn’t run, or gives a message about not finding sdcc program, then you need to check over your installation. Make sure that the sdcc bin directory is in your executable search path defined by the PATH environment setting (see section


Install trouble-shooting for suggestions). Make sure that the sdcc program is in the bin folder, if not perhaps something did not install correctly.

SDCC is commonly installed as described in section ”Install and search paths”.

Make sure the compiler works on a very simple example. Type in the following test.c program using your favorite ASCII editor: char test; void main(void) { test=0;


Compile this using the following command:

"sdcc -c test.c".

If all goes well, the compiler will generate a test.asm

and test.rel file. Congratulations, you’ve just compiled your first program with SDCC. We used the -c option to tell

SDCC not to link the generated code, just to keep things simple for this step.

The next step is to try it with the linker. Type in

"sdcc test.c

". If all goes well the compiler will link with the libraries and produce a test.ihx output file. If this step fails (no test.ihx, and the linker generates warnings), then the problem is most likely that SDCC cannot find the /usr/local/share/sdcc/lib directory (see section




If you should know why please drop us a note


2.8. INSTALL TROUBLE-SHOOTING CHAPTER 2. INSTALLING SDCC trouble-shooting for suggestions).

The final test is to ensure SDCC can use the standard header files and libraries. Edit test.c and change it to the following:

#include <string.h> char str1[10]; void main(void) { strcpy(str1, "testing");


Compile this by typing

"sdcc test.c"

. This should generate a test.ihx output file, and it should give no warnings such as not finding the string.h file. If it cannot find the string.h file, then the problem is that SDCC cannot find the /usr/local/share/sdcc/include directory (see the section


Install trouble-shooting section for suggestions). Use option --print-search-dirs to find exactly where SDCC is looking for the include and lib files.


Install Trouble-shooting


If SDCC does not build correctly

A thing to try is starting from scratch by unpacking the .tgz source package again in an empty directory. Configure it like:

./configure 2>&1 | tee configure.log

and build it like:

make 2>&1 | tee make.log

If anything goes wrong, you can review the log files to locate the problem. Or a relevant part of this can be attached to an email that could be helpful when requesting help from the mailing list.


What the ”./configure” does

The ”./configure” command is a script that analyzes your system and performs some configuration to ensure the source package compiles on your system. It will take a few minutes to run, and will compile a few tests to determine what compiler features are installed.


What the ”make” does

This runs the GNU make tool, which automatically compiles all the source packages into the final installed binary executables.


What the ”make install” command does.

This will install the compiler, other executables libraries and include files into the appropriate directories. See sections


, 2.3

about install and search paths.

On most systems you will need super-user privileges to do this.


Components of SDCC

SDCC is not just a compiler, but a collection of tools by various developers. These include linkers, assemblers, simulators and other components. Here is a summary of some of the components. Note that the included simulator and assembler have separate documentation which you can find in the source package in their respective directories.



As SDCC grows to include support for other processors, other packages from various developers are included and may have their own sets of documentation.

You might want to look at the files which are installed in <installdir>. At the time of this writing, we find the following programs for gcc-builds:

In <installdir>/bin:

• sdcc - The compiler.

• sdcpp - The C preprocessor.

• asx8051 - The assembler for 8051 type processors.

• as-z80, as-gbz80 - The Z80 and GameBoy Z80 assemblers.

• aslink -The linker for 8051 type processors.

• link-z80, link-gbz80 - The Z80 and GameBoy Z80 linkers.

• s51 - The ucSim 8051 simulator. Not available on Win32 platforms.

• sdcdb - The source debugger. Not available on Win32 platforms.

• packihx - A tool to pack (compress) Intel hex files.

In <installdir>/share/sdcc/include

• the include files

In <installdir>/share/sdcc/lib

• the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled relocatables.

In <installdir>/share/sdcc/doc

• the documentation

As development for other processors proceeds, this list will expand to include executables to support processors like AVR, PIC, etc.


sdcc - The Compiler

This is the actual compiler, it in turn uses the c-preprocessor and invokes the assembler and linkage editor.


sdcpp - The C-Preprocessor

The preprocessor is a modified version of the GNU preprocessor. The C preprocessor is used to pull in #include sources, process #ifdef statements, #defines and so on.


asxxxx, aslink, link-xxx - The Assemblers and Linkage Editors

This is retargettable assembler & linkage editor, it was developed by Alan Baldwin. John Hartman created the version for 8051, and I (Sandeep) have made some enhancements and bug fixes for it to work properly with SDCC.


s51 - The Simulator

S51 is a freeware, opensource simulator developed by Daniel Drotos. The simulator is built as part of the build process. For more information visit Daniel’s web site at: embedded/s51

. It currently supports the core mcs51, the Dallas DS80C390 and the Phillips XA51 family. S51 is currently not available on Win32 platfors.




sdcdb - Source Level Debugger

Sdcdb is the companion source level debugger. More about sdcdb in section

5 . The current version of the debugger

uses Daniel’s Simulator S51, but can be easily changed to use other simulators. Sdcdb is currently not available on

Win32 platfors.


Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF


Table of contents