Linking with C
Nic Webb
nwebb-pop at mail1.sjc.ligifts.com
Thu Nov 16 01:17:53 CET 2000
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 at 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
>
More information about the Gpc
mailing list