home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!news.tek.com!vice!bobbe
- From: bobbe@vice.ICO.TEK.COM (Robert Beauchaine)
- Newsgroups: comp.lang.pascal
- Subject: Re: Linking C++ .OBJ's with TP 5.5
- Message-ID: <11021@vice.ICO.TEK.COM>
- Date: 23 Dec 92 17:55:52 GMT
- References: <BzosFE.KA6@eis.calstate.edu>
- Organization: Tektronix, Inc., Beaverton, OR.
- Lines: 78
-
- In article <BzosFE.KA6@eis.calstate.edu> mparanj@eis.calstate.edu (Milind Paranjpe) writes:
- >Hello:
- >
- >I'm trying to link in functions written in Borland C++ 2.0 into a Pascal
- >program (TP 5.5). I keep getting errors saying that the public symbols in
- >the C++ .OBJ file aren't in the CODE segment. Looking at the C++ manual, all
- >the code goes in a segment called _TEXT. Is there a way to change this so
- >TP 5.5 can recognize and use the C++ function??
- >
-
- This question comes up often enough that I've created a FAQ answer:
- I've never tried to link C++ code, but with what I know of C++, by
- the time you've gotten an object file it shouldn't be any
- different than a straight C program.
-
- The answer is a qualified yes. Yes, you can call C code, but you
- probably won't want to. Unless you've purchased the runtime library
- for your C compiler and changed the segment naming conventions, you
- are not going to be able to call *any* of the C runtime library
- routines. This includes everything from printf() to malloc().
-
- If you still want to call C code, you need to do the following:
-
- 1. Your C code can have no initialized data (i.e, no initialized
- statics). This was true for Turbo 5 and 5.5. I believe that
- Borland has changed the linker enough to remove this restriction
- with Turbo 6, but I have not verified that fact.
-
- 2. All symbols must have valid Pascal identifiers.
-
- 3. The object file cannot contain groups or classes.
-
- To accomplish the above, pass the following compiler directives to
- TCC at compile time:
-
- { Here's where I'm not sure of the differences between TCC and
- BCC, if there are any }
-
-
- -wrvl enable all warnings
- -p use pascal calling convention
- -k- turn off standard stack frame
- -r use register variables
- -u- turn off underscore generation
- -c compile to .obj file (no .exe)
- -ms use small memory model
- -zCCODE name code segment CODE
- -zP no code group generation
- -zA no code class generation
- -zRCONST name the static data segment CONST
- -zS no data group generation
- -zT no data class generation
- -zDDATA name data segment DATA
- -zG no BSS group
- -zB no BSS class
-
-
- When compiled, link in the object code with a $L compiler directive in
- Turbo. Then create an external procedure declaration.
-
- I would suggest returning var parameters from C rather than having
- functions return values unless you know the compiler's return method
- for the various sized data types.
-
- In short, for the functionality you gain by calling procedures from
- C as opposed to the restrictions, I would stick to assembler until
- Borland makes Turbo Pascal with an external linker that allows you
- more flexibility. But don't hold your breath.
-
- /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
-
- Bob Beauchaine bobbe@vice.ICO.TEK.COM
-
- C: The language that combines the power of assembly language with the
- flexibility of assembly language.
-
- Real friends don't let friends use UNIX.
-
-