There is an example C code linking to two static libraries. This code is compiled via a Makefile. The makefile generates first of all an object file from source file, and then covert it to an executable file via the following commands. In addition, links two libraries to the compiled code:
cc -I. -DUNIX -c cademo1.c
g77 -o cademo1 cademo1.o ../libChemAppC.a ../libLChemApp.a
These two commands are the output of the Makefile. If I can run them by my own, they work.
Now, I need to compile the code by gcc:
$ gcc -static cademo1.c -L.. -lChemAppC -lLChemApp -o cademo1
But it makes hundreds of such errors:
.
.
.
rtrnshdr.f:(.text+0x1551): undefined reference to `s_rsue'
rtrnshdr.f:(.text+0x1564): undefined reference to `do_uio'
rtrnshdr.f:(.text+0x156c): undefined reference to `e_rsue'
../libLChemApp.a(bindummy.o): In function `tqhbix_':
bindummy.f:(.text+0x11): undefined reference to `s_copy'
../libLChemApp.a(dt.o): In function `tqdtforid_':
dt.f:(.text+0x11): undefined reference to `s_copy'
../libLChemApp.a(dt.o): In function `tqhdt_':
dt.f:(.text+0x5c): undefined reference to `G77_date_and_time_0'
dt.f:(.text+0x86): undefined reference to `s_wsfi'
dt.f:(.text+0x99): undefined reference to `do_fio'
dt.f:(.text+0xad): undefined reference to `do_fio'
dt.f:(.text+0xc3): undefined reference to `do_fio'
dt.f:(.text+0xd7): undefined reference to `do_fio'
dt.f:(.text+0xed): undefined reference to `do_fio'
../libLChemApp.a(dt.o):dt.f:(.text+0x101): more undefined references to `do_fio' follow
../libLChemApp.a(dt.o): In function `tqhdt_':
dt.f:(.text+0x173): undefined reference to `e_wsfi'
../libLChemApp.a(dt.o): In function `tqhdat_':
dt.f:(.text+0x1f4): undefined reference to `G77_date_and_time_0'
../libLChemApp.a(dt.o): In function `tqhgmy_':
dt.f:(.text+0x22d): undefined reference to `G77_date_and_time_0'
../libLChemApp.a(progcali.o): In function `tqhpnid_':
progcali.f:(.text+0x17): undefined reference to `s_copy'
progcali.f:(.text+0x2c): undefined reference to `s_copy'
progcali.f:(.text+0x44): undefined reference to `s_copy'
progcali.f:(.text+0x5c): undefined reference to `s_copy'
progcali.f:(.text+0x74): undefined reference to `s_copy'
../libLChemApp.a(progcali.o):progcali.f:(.text+0xf7): more undefined references to `s_copy' follow
collect2: error: ld returned 1 exit status
Could anyone tell me how can I compile a program by gcc which can be properly compiled by cc and g77?
Is there any compiler args which can be added to gcc to functions the same as g77?
As Etan mentions,
g77is a FORTRAN compiler. You are using it as a linker here (linking objects and libraries together into a program). This, plus your error messages, make pretty clear that at least one of those libraries you're linking are written in FORTRAN.The easiest solution is to continue to use
g77to link. The linker will add special compiler-specific libraries to the program for you; for example if you link withg++(the C++ compiler/linker) then it will add in the standard STL library, etc.You don't say why using
g77is not acceptable, but if it's not you'll have to figure out what extra librariesg77is linking and add them to yourgcclink line by hand.I don't have it installed so I can't tell you what they are, but you can run
g77 -v ...and it should show you the command theg77front-end uses to invoke the linker: the extra libraries you need should show up there.