I'm using the example I saw in the GNU pascal documentation on how to link pascal with C (calling a C function from pascal). The example uses "asmname", which I know very little about.
When I compile the .pas file, I get a slew of errors saying: comma missing after identifier `Asmname' parse error before character constant
(that shows up once for every line I have asmname on...
when I add the --automake option to the gpc command line, it also tells me that it can't execute my program (no such file or directory). I can't compile without automake because for some reason gpc isn't able to find any valid units without it (omitting it gives me "module/unit interface `Gpc' could not be imported").
can anyone help out? -Nic
Nic Webb wrote:
I'm using the example I saw in the GNU pascal documentation on how to link pascal with C (calling a C function from pascal). The example uses "asmname", which I know very little about.
When I compile the .pas file, I get a slew of errors saying: comma missing after identifier `Asmname' parse error before character constant
(that shows up once for every line I have asmname on...
I assume you meaan the example from the section "Importing Libraries from Other Languages" (CallCDemo etc.).
Did you use some dialect option like `--borland-pascal'? In this case, `asmname' is disabled (like all features that BP doesn't know).
If you don't use such an option, and have a recent GPC version, this shouldn't happen. Please post some sample code then...
(If you need to use `asmname' in a file otherwise compiled with `--borland-pascal', you can change the dialect temporarily with compiler options `{$gnu-pascal}' and `{$borland-pascal}' in the source. Though most of the time, you should be fine compiling without `--borland-pascal' at all, unless you use some very "dirty" BP misfeatures...)
when I add the --automake option to the gpc command line, it also tells me that it can't execute my program (no such file or directory). I can't compile without automake because for some reason gpc isn't able to find any valid units without it (omitting it gives me "module/unit interface `Gpc' could not be imported").
That's normal. Just use `--automake', and don't worry about it...
Frank
actually, I found the problem and discovered another. THe issue was that I was calling the subroutine without ()'s... I figured that out by running my own C include test... The new problem is that I can't figure out how to compile a .pas file with gpc so that it doesn't require a main method (begin end.)... gpc -c file.pas will give me a happy object file that's easily imported into c, but when file.pas has a main method, it conflicts with the one in my main c program...
I've been looking up compiler directives and command line options for the past hour and haven't found anything... -Nic
On Wed, 15 Nov 2000, Frank Heckenbach wrote:
Nic Webb wrote:
I'm using the example I saw in the GNU pascal documentation on how to link pascal with C (calling a C function from pascal). The example uses "asmname", which I know very little about.
When I compile the .pas file, I get a slew of errors saying: comma missing after identifier `Asmname' parse error before character constant
(that shows up once for every line I have asmname on...
I assume you meaan the example from the section "Importing Libraries from Other Languages" (CallCDemo etc.).
Did you use some dialect option like `--borland-pascal'? In this case, `asmname' is disabled (like all features that BP doesn't know).
If you don't use such an option, and have a recent GPC version, this shouldn't happen. Please post some sample code then...
(If you need to use `asmname' in a file otherwise compiled with `--borland-pascal', you can change the dialect temporarily with compiler options `{$gnu-pascal}' and `{$borland-pascal}' in the source. Though most of the time, you should be fine compiling without `--borland-pascal' at all, unless you use some very "dirty" BP misfeatures...)
when I add the --automake option to the gpc command line, it also tells me that it can't execute my program (no such file or directory). I can't compile without automake because for some reason gpc isn't able to find any valid units without it (omitting it gives me "module/unit interface `Gpc' could not be imported").
That's normal. Just use `--automake', and don't worry about it...
Frank
-- Frank Heckenbach, frank@g-n-u.de, http://fjf.gnu.de/ GPC To-Do list, latest features, fixed bugs: http://agnes.dida.physik.uni-essen.de/~gnu-pascal/todo.html
Nic Webb wrote:
The new problem is that I can't figure out how to compile a .pas file with gpc so that it doesn't require a main method (begin end.)... gpc -c file.pas will give me a happy object file that's easily imported into c, but when file.pas has a main method, it conflicts with the one in my main c program...
If you write a unit instead of a program, it will not have a `main' function.
When compiling a unit, please supply the `-c' option, so GPC will just produce an `.o' file and will not try to link.
Hope this helps,
Peter
Peter Gerwinski wrote:
Nic Webb wrote:
The new problem is that I can't figure out how to compile a .pas file with gpc so that it doesn't require a main method (begin end.)... gpc -c file.pas will give me a happy object file that's easily imported into c, but when file.pas has a main method, it conflicts with the one in my main c program...
If you write a unit instead of a program, it will not have a `main' function.
When compiling a unit, please supply the `-c' option, so GPC will just produce an `.o' file and will not try to link.
Or if you compile a Pascal program, you can use the `gpc-main' directive. (See gpc_c_* in the demos directory.)
Frank
Yeah, I've got a few test cases I'm trying to get to work with that... I've got a unit1.pas which just has a procedure called printhi in it (just prints something to stdout).
so, I compile the unit with gpc
gpc -c unit1.pas
and get the object file. Now I build a header file for it defining printhi as an external subroutine: extern void printhi(); then compile the c source that uses printhi in it's main block, linking in the object file I created before like so:
gcc -i unit1.o useunit.c
This is where things go ary. I get errors saying that the following symbols are undefined: stdout write check_inoutres collect_flag collect inoutres
are these in some unit that I need to include? should I include gpc.o in my gcc command line like I did unit1.o?
-Nic
On Wed, 15 Nov 2000, Peter Gerwinski wrote:
Nic Webb wrote:
The new problem is that I can't figure out how to compile a .pas file with gpc so that it doesn't require a main method (begin end.)... gpc -c file.pas will give me a happy object file that's easily imported into c, but when file.pas has a main method, it conflicts with the one in my main c program...
If you write a unit instead of a program, it will not have a `main' function.
When compiling a unit, please supply the `-c' option, so GPC will just produce an `.o' file and will not try to link.
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-20001115 GnuPG key fingerprint: 9E7C 0FC4 8A62 5536 1730 A932 9834 65DB 2143 9422 keys: http://www.gerwinski.de/pubkeys/ - AntiSpam: http://spam.abuse.net
Nic Webb wrote:
Yeah, I've got a few test cases I'm trying to get to work with that... I've got a unit1.pas which just has a procedure called printhi in it (just prints something to stdout).
so, I compile the unit with gpc
gpc -c unit1.pas
and get the object file. Now I build a header file for it defining printhi as an external subroutine: extern void printhi(); then compile the c source that uses printhi in it's main block, linking in the object file I created before like so:
gcc -i unit1.o useunit.c
This is where things go ary. I get errors saying that the following symbols are undefined: stdout write check_inoutres collect_flag collect inoutres
are these in some unit that I need to include? should I include gpc.o in my gcc command line like I did unit1.o?
You need to link -lgpc and -lm if you do the linking with gcc -- but you can just as well do it with gpc, then this happens automatically.
You also need to call some initializers. Please see the (working!) examples I mentioned, and the comments in gpc-in-c.h
Frank
I've
On Wed, 15 Nov 2000, Frank Heckenbach wrote:
Nic Webb wrote:
Yeah, I've got a few test cases I'm trying to get to work with that... I've got a unit1.pas which just has a procedure called printhi in it (just prints something to stdout).
so, I compile the unit with gpc
gpc -c unit1.pas
and get the object file. Now I build a header file for it defining printhi as an external subroutine: extern void printhi(); then compile the c source that uses printhi in it's main block, linking in the object file I created before like so:
gcc -i unit1.o useunit.c
This is where things go ary. I get errors saying that the following symbols are undefined: stdout write check_inoutres collect_flag collect inoutres
are these in some unit that I need to include? should I include gpc.o in my gcc command line like I did unit1.o?
You need to link -lgpc and -lm if you do the linking with gcc -- but you can just as well do it with gpc, then this happens automatically.
You also need to call some initializers. Please see the (working!) examples I mentioned, and the comments in gpc-in-c.h
Frank
-- Frank Heckenbach, frank@g-n-u.de, http://fjf.gnu.de/ GPC To-Do list, latest features, fixed bugs: http://agnes.dida.physik.uni-essen.de/~gnu-pascal/todo.html
Okay... This is what I've read and figured out about how to make this work...
I compile gpc_c_unit.pas wihout linking like so:
gpc -c gpc_c_unit.pas
I've got a gpc_c_unit.o file now that I can link into compilation of gpc_c_c.c like so:
gcc -i gpc_c_unit.o gpc_c_c.c
firstly, during compilation of gpc_c_unit.pas, I get a parsing error for every line that "asmname" is on, the typical: gpc_c_unit.pas:35: parse error before character constant gpc_c_unit.pas:38: comma missing after identifier `Asmname'
that I've seen a million times before... Previously, I attributed this to a versioning problem between gpc and gcc... But gpc is now using the correct version of gcc (2.95.2) and reading from the right directory.
Someone suggested that I install the newest alpha version... So I downloaded it and tried it out. Recompiling gcc turned out to be an even bigger problem, I've been getting very strange errors saying there's an error in libiberty/config.h, but most recently an error message stating that there was no "pascal" to build... (I obtained instructions from the readme file in the alpha directory, and from the installation files from the gpc version, both sets of instructions are vastly different, but the instructions from the README got me past the configuration process).
I don't see how rebuilding gcc can know that the pascal files are in the p directory off of the gcc source dir. The version INSTALL file told me I would get prompted, which never happened...
I have however, trimmed down gpc_c_unit.pas, and gotten it to compile successfully by slicing it down so only the procedure declarations remain (cutting out the var declaration and the "to begin do", "to begin end" blocks).
in which cases, I get far enough to compile the C program, and receive a slew of undefined symbol errors (seemingly anything related to pascal is undefined, even stdout).
I feel like I'm sounding stupid and asking incompetant questions because it seems everyone else easily gets beyond this point without any problems... What I really need is current documentation, something to tell me how to install gpc correctly if it's not already, but what document should I use? and if it's one that I am using, I need to figure out what I'm doing wrong to cause these obscure gcc rebuild errors...
My issues are that I only have a fair degree of understanding when it comes to building compilers and handling low-level code... I know C fairly well, and I know pascal, but anything I know about linking objects into a compiler run I learned just recently when I first downloaded gpc... So it's entirely possible that I'm just compiling things incorrectly... If so, smack me and tell me to be quiet, please :)
Can anyone point me in the right direction or towards some documentation that is current and should work?
-Nic
On Wed, 15 Nov 2000, Frank Heckenbach wrote:
Nic Webb wrote:
Yeah, I've got a few test cases I'm trying to get to work with that... I've got a unit1.pas which just has a procedure called printhi in it (just prints something to stdout).
so, I compile the unit with gpc
gpc -c unit1.pas
and get the object file. Now I build a header file for it defining printhi as an external subroutine: extern void printhi(); then compile the c source that uses printhi in it's main block, linking in the object file I created before like so:
gcc -i unit1.o useunit.c
This is where things go ary. I get errors saying that the following symbols are undefined: stdout write check_inoutres collect_flag collect inoutres
are these in some unit that I need to include? should I include gpc.o in my gcc command line like I did unit1.o?
You need to link -lgpc and -lm if you do the linking with gcc -- but you can just as well do it with gpc, then this happens automatically.
You also need to call some initializers. Please see the (working!) examples I mentioned, and the comments in gpc-in-c.h
Frank
-- Frank Heckenbach, frank@g-n-u.de, http://fjf.gnu.de/ GPC To-Do list, latest features, fixed bugs: http://agnes.dida.physik.uni-essen.de/~gnu-pascal/todo.html
Hi
On Thu, 16 Nov 2000, Nic Webb wrote:
Someone suggested that I install the newest alpha version... So I downloaded it and tried it out. Recompiling gcc turned out to be an even bigger problem, I've been getting very strange errors ...
The safest way is to start with a clean tar.gz of gcc. Use the cookbook routine in the FAQ.
Before you use the newly upgraded gpc, carefully delete any .o and .gpi files from the old units. (check the units directory). Do not know if the problem is "automake" or "ld", but apparently the file dates of the .o and .gpi files are not checked against the coresponding .pas files, so if there were any changes you will get some very strange error messages.
I don't see how rebuilding gcc can know that the pascal files are in the p directory off of the gcc source dir.
configure looks in all the directories in gcc*/gcc/ for a file called "Make-lang.in". If it finds it, it looks in there for the name of the language it can build. Thus the pascal files are in p, the fortran files are in f, etc.
have fun Russ