cl65 Users Guide
1. Overview
cl65 is a frontend for cc65, ca65 and ld65. While you may not use the full power of the tools when calling them through cl65, most features are available, and the use of cl65 is much simpler.
2. Basic Usage
The cl65 compile and link utility may be used to convert, compile, assemble and link files. While the separate tools do just one step, cl65 knows how to build object files from C files (by calling the compiler, then the assembler) and other things.
--------------------------------------------------------------------------- Usage: cl65 [options] file [...] Short options: -c Compile and assemble but don't link -d Debug mode -g Add debug info -h Help (this text) -l name Create an assembler listing file -m name Create a map file -o name Name the output file -r Enable register variables -t sys Set the target system -u sym Force an import of symbol 'sym' -v Verbose mode -vm Verbose map file -C name Use linker config file -Cl Make local variables static -D sym[=defn] Define a preprocessor symbol -E Stop after the preprocessing stage -I dir Set a compiler include directory path -L path Specify a library search path -Ln name Create a VICE label file -O Optimize code -Oi Optimize code, inline more code -Or Optimize code, honour the register keyword -Os Optimize code, inline standard funtions -S Compile but don't assemble and link -T Include source as comment -V Print the version number -W name[,...] Supress compiler warnings -Wa options Pass options to the assembler -Wc options Pass options to the compiler -Wl options Pass options to the linker Long options: --add-source Include source as comment --all-cdecl Make functions default to __cdecl__ --asm-args options Pass options to the assembler --asm-define sym[=v] Define an assembler symbol --asm-include-dir dir Set an assembler include directory --bin-include-dir dir Set an assembler binary include directory --bss-name seg Set the name of the BSS segment --cc-args options Pass options to the compiler --cfg-path path Specify a config file search path --check-stack Generate stack overflow checks --code-name seg Set the name of the CODE segment --codesize x Accept larger code by factor x --config name Use linker config file --cpu type Set cpu type (65C02, 65SC02) --create-dep name Create a make dependency file --create-full-dep name Create a full make dependency file --data-name seg Set the name of the DATA segment --debug Debug mode --debug-info Add debug info --feature name Set an emulation feature --force-import sym Force an import of symbol 'sym' --help Help (this text) --include-dir dir Set a compiler include directory path --ld-args options Pass options to the linker --lib-path path Specify a library search path --listing name Create an assembler listing file --list-bytes n Number of bytes per assembler listing line --mapfile name Create a map file --no-sdk-libs Link only the core SDK library, not the optional set --no-target-lib Don't link the target library --obj file Link this object file --obj-path path Specify an object file search path --print-target-path Print the target file path --register-space b Set space available for register variables --register-vars Enable register variables --rodata-name seg Set the name of the RODATA segment --sdk-libs file Use an alternative SDK library manifest --signed-chars Default characters are signed --start-addr addr Set the default start address --static-locals Make local variables static --target sys Set the target system --version Print the version number --verbose Verbose mode ---------------------------------------------------------------------------
Most of the options have the same meanings as the corresponding compiler,
assembler, and linker options. See the documentation for those tools for an
explanation. If an option is available for more than one of the tools, it
is set for all tools where it is available. One example for that is -v:
The compiler, the assembler, and the linker are all called with the -v
switch.
There are a few remaining options that control the behaviour of cl65:
-E-
This option is passed to the cc65 compiler; and, it forces cl65 to stop before the assembly step. That means that C-level preprocessor directives are obeyed; and, macros are expanded. But, the C source isn't compiled. If the
-ooption isn't used, then the C code results are written into files with a ".i" suffix on their base names. Assembler files, object files, and libraries given on the command line are ignored. -S-
This option forces cl65 to stop before the assembly step. That means that C files are translated into assembler files; but, nothing more is done. Assembler files, object files, and libraries given on the command line are ignored.
-c-
This option forces cl65 to stop after the assembly step. That means that C and assembler files given on the command line are translated into object files; but, there is no link step. Object files and libraries given on the command line are ignored.
-o name-
The -o option is used for the target name in the final step. That causes problems if the linker will not be called, and there are several input files on the command line. In that case, the name given with -o will be used for all of them, which makes the option pretty useless. You shouldn't use
-owhen more than one output file is created. -t sys, --target sys-
Accepted for backwards compatibility only. The only valid argument is
lynx; any other target system is an error. Because this SDK always targets the Atari Lynx, the option has no effect on the generated output. --cpu type-
Accepted for backwards compatibility only. The valid arguments are
65C02and65SC02; any other value is an error. The argument is otherwise ignored, because the toolchain always builds for the Lynx's 65SC02. --print-target-path-
This option prints the absolute path of the target file directory, and exits then. It is supposed to be used with shell backquotes or the GNU make shell function. That way, you can write build scripts or Makefiles accessing target files without any assumption about the cc65 installation path.
--no-target-lib-
This option tells the cl65 to not include the target library into the list of libraries.
--no-sdk-libs-
By default cl65 links the whole Lynx Game Development SDK library set automatically: at the link step it appends every archive named in the SDK library manifest (
lib/lynx-sdklibs.list), in dependents-first / core-last order, instead of only the corelynx.lib. Because ld65 extracts only the object modules a program actually references, the optional subsystems (graphics, audio, compress, math) a program does not touch contribute nothing to the output — so a program links whatever it uses with no-lflags. This option turns that off: only the corelynx.libis appended, restoring the fully explicit workflow where you name each optional library yourself with-l(in dependents-first, core-last order). If the manifest is absent, cl65 behaves as if--no-sdk-libswere given. User-named libraries are linked ahead of the automatic set and override it (an archive you name is not added twice). Seedesign/LYNX_CL65_AUTOLIBS_DESIGN.md. --sdk-libs file-
Use
fileas the SDK library manifest instead of the defaultlynx-sdklibs.listfound in the library search path. The file lists one archive per line, in the order cl65 hands them to the linker (dependents first, core last); blank lines and lines beginning with#are ignored. Use this to extend the automatic set with an out-of-tree library without editing the shipped manifest. -Wa options, --asm-args options-
Pass options directly to the assembler. This may be used to pass options that aren't directly supported by cl65. Several options may be separated by commas; the commas are replaced by spaces when passing them to the assembler. Beware: Passing arguments directly to the assembler might interfere with some of the defaults because cl65 doesn't parse the options passed. So, if cl65 supports an option by itself, do not pass that option to the assembler by means of the
-Waswitch. -Wc options, --cc-args options-
Pass options directly to the compiler. This may be used to pass options that aren't directly supported by cl65. Several options may be separated by commas; the commas are replaced by spaces when passing them to the compiler. Beware: Passing arguments directly to the compiler might interfere with some of the defaults because cl65 doesn't parse the options passed. So, if cl65 supports an option by itself, do not pass that option to the compiler by means of the
-Wcswitch. -Wl options, --ld-args options-
Pass options directly to the linker. This may be used to pass options that aren't directly supported by cl65. Several options may be separated by commas; the commas are replaced by spaces when passing them to the linker. Beware: Passing arguments directly to the linker might interfere with some of the defaults because cl65 doesn't parse the options passed. So, if cl65 supports an option by itself, do not pass that option to the linker by means of the
-Wlswitch.
3. More usage
Because cl65 was created to simplify the use of the cc65 development package, it tries to be smart about several things.
-
If you don't give a target system on the command line, cl65 defaults to the Atari Lynx.
-
When linking, cl65 will supply the name of the library file for the target system to the linker; so, you don't have to do that.
-
If the final step is the linker, and the name of the output file was not explicitly given, cl65 will use the name of the first input file without the extension, provided that the name of that file has an extension. So, you don't need to give the executable name in most cases; just give the name of your "main" file as the first input file.
The command line is parsed from left to right, and the actual processing tool (compiler, assembler, ...) is invoked whenever a file name is encountered. This means that only the options to the left of a file name are in effect when this file is processed. It does also mean that you're able to specify different options for different files on the command line. As an example.
cl65 -Oirs main.c -O -g module.c
translates main.c with full optimization and module.c with less optimization and debug info enabled.
The type of an input file is derived from its extension:
-
C files:
.c -
Assembler files:
.s,.asm,.a65 -
Object files:
.o,.obj -
Libraries:
.a,.lib
Please note that the program cannot handle input files with unknown file extensions.
4. Examples
The morse trainer software, which consists of one C file (morse.c) and one assembler file (irq.s) will need the following separate steps to compile into an executable named morse:
cc65 -g -Oi morse.c
ca65 -g morse.s
ca65 -g irq.s
ld65 -o morse lynx.o morse.o irq.o lynx.lib
When using cl65, this is simplified to
cl65 -g -Oi morse.c irq.s
As a general rule, you may use cl65 instead of cc65 at most times, especially in makefiles to build object files directly from C files. Use
.c.o:
cl65 -g -Oi $<
to do this.
5. Copyright
cl65 (and all cc65 binutils) are (C) Copyright 1998-2004 Ullrich von Bassewitz. For usage of the binaries and/or sources the following conditions do apply:
The full license text is reproduced verbatim, together with every other copyright notice in the distribution, on the consolidated Licenses and copyright notices page.