home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / PASCAL / MISCTI10.ZIP / TI305.ASC < prev    next >
Encoding:
Text File  |  1988-04-18  |  2.3 KB  |  101 lines

  1. PRODUCT : TURBO PROLOG     NUMBER : 305
  2. VERSION : ALL
  3.      OS : PC-DOS
  4.    DATE : OCTOBER 2, 1986
  5.  
  6.   TITLE : PROLOG TO C INTERFACE - PROGRAMS 64 & 65
  7.  
  8. For  this  example,  we  use Lattice C 2.15 or later  to  compile 
  9. EXAMPL65.C to an .OBJ file.
  10.  
  11.    Note: Large memory models must be used when linking
  12.          modules to Turbo Prolog from any other language.
  13.  
  14.  
  15. Using the C compiler issue the following commands:
  16.  
  17.    LC1 EXAMPL65 -mL -N -S -iC -b
  18.    LC2 EXAMPL65 -v
  19.  
  20. or (when using Lattice C 3.00 or later)
  21.  
  22.    LCL EXAMPLE65
  23.  
  24. This produces a new file: EXAMPL65.obj
  25.  
  26.  
  27. LINKING LATTICE C LIBRARIES
  28.  
  29. The  following  are instructions for linking Lattice  C  (version 
  30. 2.15 or 3.0) libraries with Turbo Prolog programs.  
  31.  
  32. First,  it is necessary to define certain public symbols that are 
  33. normally found in the Lattice C initialization code. Following is 
  34. an  example  subset,  that works for linking in  floating   point 
  35. libraries.
  36.  
  37. lcext.asm:
  38.  
  39. _ndpsw    equ    0
  40. _ndpcw    equ    0
  41. _fperr    equ    0
  42. _fpa        equ     0
  43. _sigfpe    equ     0
  44. _dos        equ    0
  45. _oserr    equ    0
  46. _ndp        equ    0
  47. ;;
  48. public _fperr,_fpa,_sigfpe,_dos,_oserr,_ndp,_ndpsw,_ndpcw
  49. ;;
  50. end
  51.  
  52. Assemble the file with MASM, or any other 8086 assembler.
  53.  
  54. Also,  it is necessary to set the LIB environment variable to the  
  55. directory where the Lattice libraries are located.   For example, 
  56. if your libraries are located in C:\LC\LIB, do the following:
  57.  
  58. C:\ > set lib=c:\lc\lib
  59.  
  60. Following  are  example  C  and Prolog  programs  that  use  math 
  61. libraries:
  62.  
  63. sin.c:
  64.  
  65. #include "math.h"
  66.  
  67. test(x, y)
  68. double x, *y;
  69. {
  70.     *y = sin(x);
  71. }
  72.  
  73.  
  74.  
  75. global predicates
  76.     test(real, real) - (i,o) language c
  77.  
  78. predicates
  79.     clearwindow,
  80.     test(1.57,X),
  81.     writef("X = %\n",X).
  82.  
  83. Compile the C program as follows
  84.  
  85. C:\ > lcl sin.c   ;; with Lattice 3.0
  86.  
  87. or (with Lattice version 2.15)
  88.  
  89. C:\ > lc1 sin -mL -N -S -iC -b
  90. C:\ > lc2 sin -v
  91.  
  92. Compile  the Prolog program to a .OBJ file and link the two  with 
  93. the following link command:
  94.  
  95. C:\ > link init test sin test.sym lcext,test,,prolog lcml lcl;
  96.  
  97. LCEXT.OBJ is the object module produced by the equates above. 
  98.  
  99. Different routines reference different global variables in C.OBJ.   
  100. If  any  of  these appear as  unresolved  externals,  simply  add 
  101. equates for the variables in LCEXT.ASM, and re-assemble it.