You can use Microsoft Visual C to build native applications for sanos. The
native API for sanos is a POSIX like interface, including a BSD socket interface.
Look in the API reference or in
src\include\os.h
for a list of all
the native sanos API calls. Sanos also includes an implementation of the ANSI
standard C runtime library.
If you want to build native application for sanos under sanos you can use the sanos system development kit (SDK).
The following is a guide to building a simple hello world application for sanos. This example assumes you are using Visual Studio version 7.
#include <stdio.h> int main(int argc, char *argv[]) { printf("hello world\n"); return 0; }
You can compile sanos programs from the command line. After running vsvars32.bat
you can compile the hello.c
program using the compiler from the command line:
cl -X -I\sanos\src\include hello.c /link os.lib libc.lib /LIBPATH:\sanos\lib /FIXED:NO /NODEFAULTLIB
The -X option makes the compiler ignore the standard include paths and the -I option ensures that you use the sanos include files instead. The program is linked with os.lib (the sanos os api library) and libc.lib (sanos C runtime library). The /FIXED:NO is needed to make sure that hello.exe has relocation information.
You can compile C programs for sanos under sanos by using the sanos system development kit (SDK). If you want to compile the hello world sample using the SDK you can use the following command in the sanos shell:
/usr/src/utils/samples$ cc hello.c /use/src/utils/samples$ ./hello
If you want to create a sanos project you first create a new empty project:
hello
and click 'OK'. This starts the Win32 application Wizard.Now you have created a new blank project. The project is configured for Win32 projects so we need to change some project properties to compile for sanos:
c:\sanos\src\include;$(NOINHERIT)
. This disables all
standard include directories and uses the sanos include files instead.c:\sanos\lib;$(NOINHERIT)
. This disables all
standard include directories and uses the sanos library directory instead.os.lib libc.lib $(NOINHERIT) and
'Ignore All Default Libraries'
to Yes. This will link the application with the
sanos API defined in os.lib
and the C runtime library in libc.lib
.
The libc
library also contains the startup code for the application./FIXED:NO
. By default the compiler does not generate relocation information for EXE applications,
only for DLL's. This requires that the application can be loaded at the compiled base address (default 0x400000).
This is not always possible in sanos because it uses a single process design. Setting the /FIXED:NO
linker option forces the linker to always generate relocation information to allow the application to be loaded at any address.The project is now configured for sanos applications. Add the hello.c
file to the
project and follow the procedure described above to build the application.