Linking directives (was: C Header Files -> Pascal)_(re)

Thu, 3 Apr 1997 14:38:44 +0200



Peter Gerwinski wrote:

> If you really
> must rely on C headers which change from time to time,
...or from system to system...

> it is probably
> the most reasonable thing to write a C module which uses the header
> files and exports some well-defined functions.  Then you can write a
> Unit which imports these functions as `external' functions and makes
> them accessible for your Pascal program.
That's what I did. Specifically, I needed a routine to measure the CPU time.
There is a C routine declared in time.h, but it uses a constant (#define) and
a type (typedef). The value of the constant, and even the type (int or float)
can vary on different systems, AFAIK. So the only way to use it in Pascal -
without modifying the program on every system - is to write a Pascal wrapper,
or is there any easier way?

> Another thing I did experiments with was a C program which includes
> the header files and writes out Pascal source for all constants
> defined in the header.
Wouldn't exactly make the program building process easier... :-|
And, as I see it, there's no way to handle types defined in the C header,
is there? (Well, there are not too many types in C programs, but anyway... :-)

> According to Sven Engelhardt:
> > nb. any way to issue linker-options (-lxxx -L) as preprocessor-
> > directives, so one could write rater developer-friendly code.
>
> This is planned.
>
> My idea was to make "(*$L foo.o *)" equivalent to a file name `foo.o'
> given in the command line.  One could also make "(*$L /usr/lib *)"
> equivalent to "-L /usr/lib" because GPC can check whether the given
> name refers to a file or a directory.

Something to add to this: it would be great if one could give a C file
which would be compiled (if necessary) and the resulting object linked in,
like {$L foo.c}.

Then one could make any Pascal program with --automake, even if it uses some
C files.

BTW: Is it allowed with the current versions to give C files on the command
line? I tried the following with the 0226 or 0227 version:

gpc -o homology gettime.c sysdep.pas calc_hom.pas homology.pas

With DJGPP, this works fine. But with Linux, it gives the message:

In file included from /usr/include/features.h:134,
                 from /usr/include/time.h:26,
                 from gettime.h:4,
                 from gettime.c:4:
/usr/include/sys/cdefs.h:40: parse error

However, the following works with Linux:

gcc -c gettime.c
gpc -o homology gettime.o sysdep.pas calc_hom.pas homology.pas

Is this an installation problem on my system or a general problem?
-- 
Frank Heckenbach, Erlangen, Germany
heckenb@mi.uni-erlangen.de
Turbo Pascal:   http://www.mi.uni-erlangen.de/~heckenb/programs.htm
Internet links: http://www.mi.uni-erlangen.de/~heckenb/links.htm


Frank Heckenbach (heckenb@mi.uni-erlangen.de)

HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada - Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es