0

有一个示例 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 相同的功能?

4

1 回答 1

0

正如 Etan 所提到的,g77它是一个 FORTRAN 编译器。您在这里将它用作链接器(将对象和库链接到一个程序中)。这一点,加上您的错误消息,清楚地表明您要链接的这些库中至少有一个是用 FORTRAN 编写的。

最简单的解决方法是继续使用g77链接。链接器将为您添加特殊的编译器特定库到程序中;例如,如果您使用g++(C++ 编译器/链接器)链接,那么它将添加到标准 STL 库等中。

你没有说为什么 usingg77是不可接受的,但如果不是,你将不得不弄清楚哪些额外的库g77正在链接并手动将它们添加到你的gcc链接行。

我没有安装它,所以我不能告诉你它们是什么,但你可以运行g77 -v ...它,它应该向你显示g77前端用来调用链接器的命令:你需要的额外库应该显示在那里。

于 2015-04-09T16:39:23.677 回答