sanos home

Building C programs for sanos


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. To build the hello world application you first need to create a new project. You can either use the sanos project wizard or configure the project manually.

 

Creating a sanos projects using the wizard

 

If you want to use the wizard you need to copy the following files from \sanos\vcwizard to the C:\Program Files\Microsoft Visual Studio .NET\Vc7\vcprojects directory:

If your sanos files are not located in c:\sanos you need to modify the ABSOLUTE_PATH parameter in sanoswiz.vsz. To use the wizard select File->New->Project in Visual Studio:

 

 

Select 'Sanos Project', choose name (e.g. hello) and location for project, and click 'OK'.

 

 

Choose the application type and change the Sanos SDK path to point to your location for the sanos SDK. Selecting the 'Create floppy disk boot image' option adds an image project to the solution that can build a boot floppy configured for the application. Clink 'Finish' to create a project configured for sanos. Now you are ready to start programming. Insert the following code for the hello world program:

#include <stdio.h>

int main(int argc, char *argv[])
{
  printf("hello world\n");
  return 0;
}

Select the Release configuration (in Build->Configuration Manager) and build the application. Now you should have a hello.exe file in your project release directory. If you build the image project in the solution you get a hello.flp boot image file in the release directory. Copy this image to a floppy disk using the mkfloppy tool and boot the computer from the floppy. After booting sanos the hello program executes.

If you want to try a slightly more realistic sample application for sanos you can take a look at the webserver demo application.

 

Compiling from the command line

 

You can also 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

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.

 

Compiling under sanos using the sanos SDK

 

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$ cc hello.c
\use\src$ ./hello

Manually creating sanos projects

 

If you want to create the project manually you must first create a new empty project:

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:

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.