home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / pascal / 7662 < prev    next >
Encoding:
Internet Message Format  |  1992-12-23  |  3.3 KB

  1. Path: sparky!uunet!news.tek.com!vice!bobbe
  2. From: bobbe@vice.ICO.TEK.COM (Robert Beauchaine)
  3. Newsgroups: comp.lang.pascal
  4. Subject: Re: Linking C++ .OBJ's with TP 5.5
  5. Message-ID: <11021@vice.ICO.TEK.COM>
  6. Date: 23 Dec 92 17:55:52 GMT
  7. References: <BzosFE.KA6@eis.calstate.edu>
  8. Organization: Tektronix, Inc., Beaverton,  OR.
  9. Lines: 78
  10.  
  11. In article <BzosFE.KA6@eis.calstate.edu> mparanj@eis.calstate.edu (Milind Paranjpe) writes:
  12. >Hello:
  13. >
  14. >I'm trying to link in functions written in Borland C++ 2.0 into a Pascal
  15. >program (TP 5.5).  I keep getting errors saying that the public symbols in
  16. >the C++ .OBJ file aren't in the CODE segment.  Looking at the C++ manual, all
  17. >the code goes in a segment called _TEXT.  Is there a way to change this so
  18. >TP 5.5 can recognize and use the C++ function??
  19. >
  20.  
  21.   This question comes up often enough that I've created a FAQ answer:
  22.   I've never tried to link C++ code, but with what I know of C++, by
  23.   the time you've gotten an object file it shouldn't be any
  24.   different than a straight C program.
  25.  
  26.   The answer is a qualified yes.  Yes, you can call C code, but you
  27.   probably won't want to.  Unless you've purchased the runtime library
  28.   for your C compiler and changed the segment naming conventions, you
  29.   are not going to be able to call *any* of the C runtime library 
  30.   routines.  This includes everything from printf() to malloc().
  31.  
  32.   If you still want to call C code, you need to do the following:
  33.     
  34.     1. Your C code can have no initialized data (i.e, no initialized
  35.     statics).  This was true for Turbo 5 and 5.5.  I believe that
  36.     Borland has changed the linker enough to remove this restriction
  37.     with Turbo 6, but I have not verified that fact.
  38.  
  39.     2.  All symbols must have valid Pascal identifiers.
  40.  
  41.     3.  The object file cannot contain groups or classes.
  42.  
  43.   To accomplish the above, pass the following compiler directives to 
  44.   TCC at compile time:
  45.  
  46.   { Here's where I'm not sure of the differences between TCC and
  47.   BCC, if there are any }
  48.  
  49.  
  50.     -wrvl    enable all warnings
  51.     -p        use pascal calling convention
  52.     -k-        turn off standard stack frame
  53.     -r        use register variables
  54.     -u-        turn off underscore generation
  55.     -c        compile to .obj file (no .exe)
  56.     -ms        use small memory model
  57.     -zCCODE    name code segment CODE
  58.     -zP        no code group generation
  59.     -zA        no code class generation
  60.     -zRCONST    name the static data segment CONST
  61.     -zS        no data group generation
  62.     -zT        no data class generation
  63.     -zDDATA    name data segment DATA
  64.     -zG        no BSS group
  65.     -zB        no BSS class
  66.  
  67.  
  68.   When compiled, link in the object code with a $L compiler directive in
  69.   Turbo.  Then create an external procedure declaration.
  70.  
  71.   I would suggest returning var parameters from C rather than having
  72.   functions return values unless you know the compiler's return method
  73.   for the various sized data types.
  74.  
  75.   In short, for the functionality you gain by calling procedures from
  76.   C as opposed to the restrictions, I would stick to assembler until
  77.   Borland makes Turbo Pascal with an external linker that allows you
  78.   more flexibility.  But don't hold your breath.
  79.  
  80. /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ 
  81.  
  82. Bob Beauchaine bobbe@vice.ICO.TEK.COM 
  83.  
  84. C: The language that combines the power of assembly language with the 
  85.    flexibility of assembly language.
  86.  
  87. Real friends don't let friends use UNIX.
  88.  
  89.