Hello all,
Is someone could help me about using C routines in pascal? I think I am close to the right solution but I can't manage to get it!...
So I will try to summurize all I made until now... At first, I have downloaded randlibc-1.3.tar.gz. After having unpacked this file, a randlib.c directory was created and it contains: HOWTOGET* README* doc/ src/ test/
In src, I have compiled com.c, linpack.c and randlib.c and put them in a library lirandlib.a Then, I have move librandlib.a into /usr/local/lib and randlib.h in /usr/local/include.
Actually, I would like to use a fonction named "genbet" in the randlib.c. For that, I have made a little program beta.pas:
unit beta; interface {$L /usr/local/include/randlib.h} function genbet(x,y:shortreal):shortreal;C; implementation end.
and test.pas: uses beta; begin writeln(genbet(100,150)); end.
When I compile the first one, the following message appears: Undefined first referenced symbol in file main /usr/local/lib/gcc-lib/sparc-sun-solaris2.7/ 2.95.2/crt1.o ld: fatal: Symbol referencing errors. No output written to beta collect2: ld returned 1 exit status
And for the second one: test.p:4: object file `/usr/local/include/randlib.o' not found test.p:4: object file `/usr/local/include/randlib.o' not found
"extern float genbet(float aa,float bb)" is in randlib.h and the program is written in randlib.c.
I really need your help,
Nathalie
________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
Nathalie Jarosz wrote:
Actually, I would like to use a fonction named "genbet" in the randlib.c. For that, I have made a little program beta.pas:
unit beta; interface {$L /usr/local/include/randlib.h}
{$L randlib }
Undefined first referenced symbol in file main
Add the `-c' option to this compilation.
And for the second one: test.p:4: object file `/usr/local/include/randlib.o' not found test.p:4: object file `/usr/local/include/randlib.o' not found
See above. If you keep getting error messages, make sure that `randlib.a' is found (it is when it is located in /usr/lib or in /usr/local/lib/).
Hope this helps,
Peter
Hi,
Would it be sufficient to put function genbet(x,y:shortreal):shortreal;C; in the calling program? Is it necessary to have the wrapper unit? If yes, why is a wrapper needed?
Thanks.
On Fri, 7 Jul 2000, Nathalie Jarosz wrote:
Actually, I would like to use a fonction named "genbet" in the randlib.c. For that, I have made a little program beta.pas:
unit beta; interface {$L /usr/local/include/randlib.h} function genbet(x,y:shortreal):shortreal;C; implementation end.
and test.pas:
uses beta; begin writeln(genbet(100,150)); end.
7-Jul-00 08:53 you wrote:
Hi,
Would it be sufficient to put function genbet(x,y:shortreal):shortreal;C; in the calling program?
Yes.
Is it necessary to have the wrapper unit?
No.
If yes, why is a wrapper needed?
Why units are needed at all ? Why .h file are used in C programming ? To have ONE definition of function, of course. So you do not need to change 10'000 files when genbet definition will be changed...
Thanks.
On Fri, 7 Jul 2000, Nathalie Jarosz wrote:
Actually, I would like to use a fonction named "genbet" in the randlib.c. For that, I have made a little program beta.pas:
unit beta; interface {$L /usr/local/include/randlib.h} function genbet(x,y:shortreal):shortreal;C; implementation end.
and test.pas:
uses beta; begin writeln(genbet(100,150)); end.
-- Claude Marinier, Information Technology Group claude.marinier@dreo.dnd.ca Defence Research Establishment Ottawa (DREO) (613) 998-4901 FAX 998-2675 3701 Carling Avenue, Ottawa, Ontario K1A 0Z4 http://www.dreo.dnd.ca
7-Jul-00 14:36 you wrote:
Hello all,
Is someone could help me about using C routines in pascal? I think I am close to the right solution but I can't manage to get it!...
You really close to right solution.
So I will try to summurize all I made until now... At first, I have downloaded randlibc-1.3.tar.gz. After having unpacked this file, a randlib.c directory was created and it contains: HOWTOGET* README* doc/ src/ test/
In src, I have compiled com.c, linpack.c and randlib.c and put them in a library lirandlib.a Then, I have move librandlib.a into /usr/local/lib and randlib.h in /usr/local/include.
Great. Just randlib.h is not needed for Pascal at all: you must define crrect prototypes in Pascal anyway.
Actually, I would like to use a fonction named "genbet" in the randlib.c. For that, I have made a little program beta.pas:
unit beta; interface {$L /usr/local/include/randlib.h} function genbet(x,y:shortreal):shortreal;C; implementation end.
Alost correct. Just not {$L /usr/local/include/randlib.h} but {$L randlib} ...
and test.pas: uses beta; begin writeln(genbet(100,150)); end.
When I compile the first one, the following message appears: Undefined first referenced symbol in file main /usr/local/lib/gcc-lib/sparc-sun-solaris2.7/ 2.95.2/crt1.o ld: fatal: Symbol referencing errors. No output written to beta collect2: ld returned 1 exit status
It's normal. Default last step for GPC (just like GCC) is to LINK program. You can not do THAT with unit. Just use `gpc -c' to get rid of error.
And for the second one: test.p:4: object file `/usr/local/include/randlib.o' not found test.p:4: object file `/usr/local/include/randlib.o' not found
Yeah, it's since you are written {$L /usr/local/include/randlib.h}. GPC "thinks" it's C source and thus tries to find randlinb.o and NOT tries to use existing librandlib.a ...
"extern float genbet(float aa,float bb)" is in randlib.h and the program is written in randlib.c.
You did not know ANYTHING about C, right ? .h file is more or less like interface part of Pascal's unit (or module). It's just declare functions - there are NO implemetation. .c part is more or less like implemetation part of Pascal's unit (or module). Ok, it's not part of C language definition - it's just convention, but anyway. Thus you NEVER need .h file for Pascal program: Pascal can not use .h at all. You must write substitute interface module (and your beta is more or less correct substitute module). But then Pascal need to know where to find implementation part (this part Pascal can use). For this you need $L directive. Of course it's useless to point it on .h file - it's interface, NOT implementation. You should point it to .c file, .o file or (better of all) to .a file. When you pointing to .a file you should omit path information, lib- prefix for library and .a suffix (it'a also old C linker convention). Thus your /usr/local/lib/librandlib.a will be reffered as {$L randlib} (yu can specify -L/usr/local/lib as command line parameters but it should not be needed - usually /usr/local/lib is in linker patch anyway). Hope it helps.
I really need your help,
Nathalie
Hello,
My problem is like this :
I have the C procedure in a .so file. I have the prototype declaration in a header file.
How should the declaration of the procedure be given in my pas file?What will be the types of the parameters(C or pascal)?
Regards, Anuradha
peter@gerwinski.de wrote:
Nathalie Jarosz wrote:
Actually, I would like to use a fonction named "genbet" in the randlib.c. For that, I have made a little program beta.pas:
unit beta; interface {$L /usr/local/include/randlib.h}
{$L randlib }
Undefined first referenced symbol in file main
Add the `-c' option to this compilation.
And for the second one: test.p:4: object file `/usr/local/include/randlib.o' not found test.p:4: object file `/usr/local/include/randlib.o' not found
See above. If you keep getting error messages, make sure that `randlib.a' is found (it is when it is located in /usr/lib or in /usr/local/lib/).
Hope this helps,
Peter
-- http://home.pages.de/~Peter.Gerwinski/ - G-N-U GmbH: http://www.g-n-u.de Maintainer GNU Pascal - http://home.pages.de/~GNU-Pascal/ - gpc-20000707 GnuPG key fingerprint: 9E7C 0FC4 8A62 5536 1730 A932 9834 65DB 2143 9422 keys: http://www.gerwinski.de/pubkeys/ - AntiSpam: http://spam.abuse.net
-- S.Anuradha Generic Data Tools, Alcatel Chennai. Alcanet : 2-757-7123
Anuradha wrote:
My problem is like this :
I have the C procedure in a .so file. I have the prototype declaration in a header file.
How should the declaration of the procedure be given in my pas file?What will be the types of the parameters(C or pascal)?
Please the the GPC manual, e.g. the section "Other Languages" in the "Programming chapter". Also perhaps "Data Types/Integer Types/Main Branch Integer Types" for the translation of integer types etc. for other types.
There are also examples in the `demos' directory (c_gpc_*).
If you have specific problems, be invited to post your code here...
Frank