next up previous contents index
Next: Windows instructions: Up: Creating an XSB Module Previous: Creating an XSB Module   Contents   Index

Unix instructions:

You must link your C program, which should include the main procedure, with the XSB object file located in

 $XSB_DIR/config/<your-system-architecture>/saved.o/xsb.o
Your program should include the file cinterf.h located in the XSB/emu subdirectory, which defines the routines described earlier, which you will need to use in order to talk to XSB. It is therefore recommended to compile your program with the option -I$XSB_DIR/XSB/emu.

The file $XSB_DIR/config/your-system-architecture/modMakefile is a makefile you can use to build your programs and link them with XSB. It is generated automatically and contains all the right settings for your architecture, but you will have to fill in the name of your program, etc.

It is also possible to compile and link your program with XSB using XSB itself as follows:


:- xsb_configuration(compiler_flags,CFLAGS),
        xsb_configuration(loader_flags,LDFLAGS),
        xsb_configuration(config_dir,CONFDIR),
        xsb_configuration(emudir,EMUDIR),
        xsb_configuration(compiler,Compiler),
        str_cat(CONFDIR, '/saved.o/', ObjDir),
        write('Compiling myprog.c ... '),
        shell([Compiler, ' -I', EMUDIR, ' -c ', CFLAGS, ' myprog.c ']),
        shell([Compiler, ' -o ', './myprog ',
               ObjDir, 'xsb.o ', ' myprog.o ', LDFLAGS]),
        writeln(done).
This works for every architecture and is often more convenient than using the make files.

There are simple examples of C programs calling XSB in the $XSB_DIR/examples/c_calling_XSB directory, in files cmain.c, ctest.P, cmain2.c.


next up previous contents index
Next: Windows instructions: Up: Creating an XSB Module Previous: Creating an XSB Module   Contents   Index
Baoqiu Cui
2000-04-23