home *** CD-ROM | disk | FTP | other *** search
- PRODUCT : TURBO PROLOG NUMBER : 305
- VERSION : ALL
- OS : PC-DOS
- DATE : OCTOBER 2, 1986
-
- TITLE : PROLOG TO C INTERFACE - PROGRAMS 64 & 65
-
- For this example, we use Lattice C 2.15 or later to compile
- EXAMPL65.C to an .OBJ file.
-
- Note: Large memory models must be used when linking
- modules to Turbo Prolog from any other language.
-
-
- Using the C compiler issue the following commands:
-
- LC1 EXAMPL65 -mL -N -S -iC -b
- LC2 EXAMPL65 -v
-
- or (when using Lattice C 3.00 or later)
-
- LCL EXAMPLE65
-
- This produces a new file: EXAMPL65.obj
-
-
- LINKING LATTICE C LIBRARIES
-
- The following are instructions for linking Lattice C (version
- 2.15 or 3.0) libraries with Turbo Prolog programs.
-
- First, it is necessary to define certain public symbols that are
- normally found in the Lattice C initialization code. Following is
- an example subset, that works for linking in floating point
- libraries.
-
- lcext.asm:
-
- _ndpsw equ 0
- _ndpcw equ 0
- _fperr equ 0
- _fpa equ 0
- _sigfpe equ 0
- _dos equ 0
- _oserr equ 0
- _ndp equ 0
- ;;
- public _fperr,_fpa,_sigfpe,_dos,_oserr,_ndp,_ndpsw,_ndpcw
- ;;
- end
-
- Assemble the file with MASM, or any other 8086 assembler.
-
- Also, it is necessary to set the LIB environment variable to the
- directory where the Lattice libraries are located. For example,
- if your libraries are located in C:\LC\LIB, do the following:
-
- C:\ > set lib=c:\lc\lib
-
- Following are example C and Prolog programs that use math
- libraries:
-
- sin.c:
-
- #include "math.h"
-
- test(x, y)
- double x, *y;
- {
- *y = sin(x);
- }
-
-
-
- global predicates
- test(real, real) - (i,o) language c
-
- predicates
- clearwindow,
- test(1.57,X),
- writef("X = %\n",X).
-
- Compile the C program as follows
-
- C:\ > lcl sin.c ;; with Lattice 3.0
-
- or (with Lattice version 2.15)
-
- C:\ > lc1 sin -mL -N -S -iC -b
- C:\ > lc2 sin -v
-
- Compile the Prolog program to a .OBJ file and link the two with
- the following link command:
-
- C:\ > link init test sin test.sym lcext,test,,prolog lcml lcl;
-
- LCEXT.OBJ is the object module produced by the equates above.
-
- Different routines reference different global variables in C.OBJ.
- If any of these appear as unresolved externals, simply add
- equates for the variables in LCEXT.ASM, and re-assemble it.