有一个示例 C 代码链接到两个静态库。此代码是通过 Makefile 编译的。makefile 首先从源文件生成目标文件,然后通过以下命令将其转换为可执行文件。此外,将两个库链接到已编译的代码:
cc -I. -DUNIX -c cademo1.c
g77 -o cademo1 cademo1.o ../libChemAppC.a ../libLChemApp.a
这两个命令是 Makefile 的输出。如果我可以自己运行它们,它们就可以工作。
现在,我需要通过 gcc 编译代码:
$ gcc -static cademo1.c -L.. -lChemAppC -lLChemApp -o cademo1
但它会产生数百个这样的错误:
.
.
.
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
谁能告诉我如何通过 gcc 编译一个可以由 cc 和 g77 正确编译的程序?
是否有任何编译器参数可以添加到 gcc 到与 g77 相同的功能?