[comp.lang.pascal] Linking Turbo Pascal with Microsoft C Library

A893700%CUCSC.BITNET@yalevm.ycc.yale.edu (Dominic Chow, The Chinese University of Hong Kong) (06/24/91)

Does anyone know how to link Turbo Pascal program with Microsoft C
Libraries?

I recently got a library written in Microsoft C (6.00 I think) and I know
to make use of some of the routines in my Turbo Pascal program.  I try to
extract the related object modules and $L into the program but it doesn't
work.

Thanks in advance.

Dominic Chow,
Computer Services Centre
The Chinese University of Hong Kong
A893700@CUCSC.BITNET

derek@sun4dts.dts.ine.philips.nl (derek) (06/25/91)

A893700%CUCSC.BITNET@yalevm.ycc.yale.edu (Dominic Chow, The Chinese University of Hong Kong) writes:

>Does anyone know how to link Turbo Pascal program with Microsoft C
>Libraries?

>I recently got a library written in Microsoft C (6.00 I think) and I know
>to make use of some of the routines in my Turbo Pascal program.  I try to
>extract the related object modules and $L into the program but it doesn't
>work.

It won't. Microsoft C is quite incompatible with TP (IMHO) unless something has
changed, which I doubt. It seems there's some kind of headers and things at the
assembly end that aren't allowed by TP with the $L statement. Sorry about being
vague about this - I don't have the facts to hand - just trust me - they don't
fit together.

However, all is not lost. There is something you can do if you have the source,
with a small amount of tweaking, there is a chance they will compiler in Turbo
C. I understand that Borland have improved the interface between TP6 and TPC -
there were severe restrictions with TP5.0 (and 5.5 I think, although I never had
that version). 

I've yet to try this out, although I have tried out TP5.0 and TPC. And the latter
can do some useful things. However, a big caveat - unless you have the run-time
libraries source for the C libraries, you cann't use C library calls, you can
use the pascal equivalents. Sound complicated - it is, so only worth doing if the
C code is really useful.

The other option is to convert the C code to pascal. There is a C to Pascal 
program available. I have also written a rather elementary sed script to do
the donkey work of the simple lexical translation ({ to begin, = to :=, == to =,
etc.) If the net is interested, I'll post it - it's not very big (nor, incedent-
ally is it complete).

>Thanks in advance.

You're welcome, if this _was_ any use.

>Dominic Chow,
>Computer Services Centre
>The Chinese University of Hong Kong
>A893700@CUCSC.BITNET

Best Regards, Derek Carr
DEREK@DTS.INE.PHILIPS.NL           Philips IE TQV-5 Eindhoven, The Netherlands 
Standard Disclaimers apply.

speedy@vax.oxford.ac.uk (06/25/91)

In article <27280@adm.brl.mil>, A893700%CUCSC.BITNET@yalevm.ycc.yale.edu (Dominic Chow, The Chinese University of Hong Kong) writes:
> Does anyone know how to link Turbo Pascal program with Microsoft C
> Libraries?
> 
> I recently got a library written in Microsoft C (6.00 I think) and I know
> to make use of some of the routines in my Turbo Pascal program.  I try to
> extract the related object modules and $L into the program but it doesn't
> work.
> 
> Thanks in advance.
> 
> Dominic Chow,

You will be unable to link in the object files successfully into Turbo Pascal
unless a) you can change the segement name of the code to 'CODE' (I think--Its
in the manual) b) the object code does not use any of the MicroSoft C runtime
library - since as you dont have the source code for this you will not be
able to change any segment names. I have thought about this problem often--if
anyone can see a way around this (Particulalry for Turbo C++) I would be
interested. Perhaps a dissassembler for OBJ/LIB files would help?

speedy@vax.oxford.ac.uk (06/26/91)

In article <744@sun4dts.dts.ine.philips.nl>, derek@sun4dts.dts.ine.philips.nl (derek) writes:
> A893700%CUCSC.BITNET@yalevm.ycc.yale.edu (Dominic Chow, The Chinese University of Hong Kong) writes:
> 
>>Does anyone know how to link Turbo Pascal program with Microsoft C
>>Libraries?
> 
>>I recently got a library written in Microsoft C (6.00 I think) and I know
>>to make use of some of the routines in my Turbo Pascal program.  I try to
>>extract the related object modules and $L into the program but it doesn't
>>work.
> 
> It won't. Microsoft C is quite incompatible with TP (IMHO) unless something has
> changed, which I doubt. It seems there's some kind of headers and things at the
> assembly end that aren't allowed by TP with the $L statement. Sorry about being
> vague about this - I don't have the facts to hand - just trust me - they don't
> fit together.
>

:-The reason why they dont fit together is code segment names--Turbos code
segement is called 'CODE' I think TC's is 'DATA' or 'TEXT' or something.
This is also why you cant use the TC library code or any TC code that relies
on it in TP.

           

dmurdoch@watstat.waterloo.edu (Duncan Murdoch) (06/27/91)

In article <1991Jun26.100914.834@vax.oxford.ac.uk> speedy@vax.oxford.ac.uk writes:
>>
>
>:-The reason why they dont fit together is code segment names--Turbos code
>segement is called 'CODE' I think TC's is 'DATA' or 'TEXT' or something.
>This is also why you cant use the TC library code or any TC code that relies
>on it in TP.

If you're using TP 6, the rules for segment names are considerably relaxed.
Code can be in a segment named CODE, CSEG, or something ending in _TEXT.
You can also link in initialized data, as long as the segment name is
CONST or something ending in _DATA.  Uninitialized data goes in DATA, DSEG,
or something ending in _BSS.  There are other restrictions, which are in the
manual.  The rumour I heard to explain this improvement to the linker is
that Borland wanted to write the TP 6 IDE in TP, but had to link in the
editor & compiler modules which were already in assembler and didn't
follow the TP 5 restrictions.

The hard parts (which make linking code not specially written for the purpose
nearly impossible) are that external references within the .OBJ have
to be resolved within the TP code, not in a .LIB; .LIBs aren't supported
at all; and some of the names used in libraries aren't legal names within
TP.

Stony Brook advertises TP compatibility along with mixed language support
in their Pascal+, but it hasn't been released yet, and will cost something
like $300.  TP for Windows lets you link libraries written as DLLs; that
might be the best way to go if you're willing to work within Windows.  
(Something that might be nice:  a new program loader for DOS, that can
statically load Windows-style segmented executables and referenced DLLs.)

Duncan Murdoch
dmurdoch@watstat.waterloo.edu