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.

#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.

 

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

 

Setting up sanos projects in Visual Studio

 

If you want to create a sanos project you 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.