RedHat Linux and C IMFORT programs
Mike Fitzpatrick wrote on Sep 29, 1999
> I have just successfully installed IRAF V2.11 on my RedHat 6.0
> system. Everything works fine, except that I'm having trouble
> compiling and linking to IRAF a .c code I've written, which uses the
> IMFORT library. I've gotten this code to compile, link, and run on a
> previous version of IRAF on a SPARC20, and I have the c bindings.
> When I try to make this code using fc.csh, I get the following
> messages:
>
> ---------------------
> /usr/local/iraf/iraf/unix/hlib/fc.csh -c -h -O multifit2.c
> /usr/local/iraf/iraf/unix/hlib/fc.csh -h multifit2.o -limfort -lsys
> -lvops -los -lm -o multifit2.e
> /iraf/iraf/unix/bin.redhat/libf2c.a(main.o): In function `main':
> main.o(.text+0x78): multiple definition of `main'
> multifit2.o(.text+0xed4): first defined here
> /usr/bin/ld: Warning: size of symbol `main' changed from 2391 to 159 in main.o
> /iraf/iraf/unix/bin.redhat/libf2c.a(main.o): In function `main':
> main.o(.text+0x10c): undefined reference to `MAIN__'
> collect2: ld returned 1 exit status
> make: *** [multifit2] Error 2
The problem is caused by use of the clarg() imfort procedures for
getting command line arguments. When this procedure is used it causes the
linker to load the zgcmdl() procedure which in turn requires an 'xargv'
symbol found in the libf2c main.o object file. main.o obviously also
contains a 'main' symbol which clashes with the one in your program, it
also then requires the "MAIN__" symbol which is taken to be the start of
the fortran code. From there the whole thing falls apart as you've seen.
This is not a problem when compiling Fortran imfort programs because a
fortran 'program' statement is translated by F2C into the "MAIN__" symbol
and the only 'main' symbol required comes from the libf2c.a itself.
For C imfort programs the best workaround I was able to find was to
simply avoid using the clarg procedures and deal with the arguments using
the standard argc/argv variables. I would have to experiment some more
to find a different way to link the program or rewrite the f2c main() but
I don't think these would be as reliable.
-Mike
Last post on Sep 29, 1999