How to use OSLib
Include OSLib headers
For C/C++ programs, you include the OSLib/OSLibSupport headers like as in following example:For assembler programs, this depends on the type of assembler:
#include <oslib/draw.h>
- ObjAsm, GCCSDK GCC 3.4.x As (predecessor of AsAsm) and AsAsm itself:
GET oslib/Draw.Hdr
- GCCSDK GCC 4.x (i.e. GNU AS assembler):
#include <oslib/draw.Hdr>
Acorn/Norcroft C compiler
-
Compiling C:
cc -c -afh -apcs 3/32 -IOSLibSupport:,OSLib:,C: -o foo.o foo.c
-
Assembling:
objasm -I<OSLibSupport$Dir>,<OSLib$Dir> -o foo.o -s foo.s
-
Linking AOF object files:
link foo1.o foo2.o ... OSLibSupport:OSLibSupport32.o OSLib:OSLib32.o C:stubs.o
GCCSDK GCC compiler
Using GCCSDK GCC on RISC OS:-
Compiling C with GCCSDK GCC C/C++ compiler:
gcc -c -IOSLibSupport: -IOSLib: -o foo.o foo.c
-
Assembling using GCCSDK GCC 3.4.x (AOF):
gcc -c -IOSLibSupport: -IOSLib: -xassembler-with-cpp -mapcs-32 -Wa,-objasm,-apcs32 -o foo.o foo.s
-
Assembling using GCCSDK GCC 4.x (ELF):
gcc -c -IOSLibSupport: -IOSLib: -xassembler-with-cpp -o foo.o foo.s
-
Assembling using AsAsm:
asasm -I<OSLibSupport$Dir>,<OSLib$Dir> -o foo.o -s foo.s
-
Linking using GCCSDK GCC 3.4.x (AOF):
gcc -o final foo1.o foo2.o ... OSLibSupport:OSLibSupport32.o OSLib:OSLib32.o
-
Linking using GCCSDK GCC 4.x (ELF):
gcc -o final foo1.o foo2.o ... -LOSLibSupport: -lOSLibSupport32 -LOSLib: -lOSLib32
- Replace "-IOSLibSupport: -IOSLib:" by "-I$GCCSDK_INSTALL_ENV/include"
and "-LOSLibSupport:" + "-LOSLib:" by "-L$GCCSDK_INSTALL_ENV/lib".
The environment variable GCCSDK_INSTALL_ENV gets defined when building the cross-compiler and holds all the headers and libraries of programs built with the cross-compiler. - For GCCSDK GCC 4.x, replace "gcc" by "arm-unknown-riscos-gcc"
When using GCCSDK GCC 4.x including AsAsm with "-elf" or without "-aof" option (as the "-elf" option is default), you need to use ELF based OSLib binaries. This is only possible from OSLib 7.00 onwards.
Furthermore, when you are using the ELF OSLib binaries, there are three different set of binaries depending on when you want to use the SharedCLibrary for application usage, SharedCLibrary for module usage or UnixLib usage:
- Using -mlibscl gcc option, i.e. using SharedCLibrary for application usage. This means hardfloat fpa binaries.
- Using -mmodule gcc option, i.e. using SharedCLibrary for module usage. This means hardfloat fpa module binaries.
- Using -munixlib or no -mlibscl/-mmodule gcc option, i.e. using UnixLib. This means softfloat binaries.