Nathalie Jarosz wrote:
You need to link the C code. For a simple C file, you can insert `{$L foo.c}' into the unit, and GPC will automatically compile the C file. For a library libbar.a, you can use `{$L bar}' in the source which is equivalent to `-lbar' on the command line.
I am not sure to understand. Do I have to put {$L randlib.c} in beta.p like this:
If you have a self-contained file randlib.c. If randlib.c requires other C files, say baz.c, add `{$L baz.c}' as well. However, if you have librandlib.a instead, read on.
unit beta; interface {$L randlib.c} function genbet(x,y:shortreal):shortreal;C; implementation end.
and keep my program called 'test' like this:
program betadev; uses beta; begin writeln(genbet(100,150)); end.
and after if I compile the first one, the following message appears: beta.p:5: file `randlib.c' not found
and for the second one: Undefined first referenced symbol in file genbet /var/tmp/cc5OaGYv1.o ld: fatal: Symbol referencing errors. No output written to test collect2: ld returned 1 exit status
When you say "For a library libbar.a, you can use `{$L bar}' in the source which is equivalent to `-lbar' on the command line.", what is the source in this case?
GPC doesn't care. For libraries, it expects them to be compiled already. I.e., if you have librandlib.a (a compiled library), add `{$L randlib}' in the Pascal source.
If you have the sources for librandlib, compile them first (according to the (hopefully) accompanying instructions), to get librandlib.a (or librandlib.so, a shared library, which can also be used by `{$L randlib}').
Frank