如何让 gfortran 与 i386 兼容?我遇到了“未定义引用”错误。如何获取兼容的 libf2c?

如何让 gfortran 与 i386 兼容?我遇到了“未定义引用”错误。如何获取兼容的 libf2c?

我在一台 64 位机器上安装了 Ubuntu 14.04。我想运行gfortran -m32我的 f77 fortran 代码,该代码也使用 i386 CERN 库。我下载了 Ubuntu 软件包 cernlib、lib32gfortran-4.8-dev 和 gcc-multilib。但是当我运行命令时出现了如下错误:

$ gfortran -m32 -O -o out10 MBpart1ep0.f -L. -lmathlib -lkernlib -Lcuba

/tmp/ccs5Njbz.o: In function `MAIN__':
MBpart1ep0.f:(.text+0x82): undefined reference to `cuhre_'
//usr/local/lib/libmathlib.a(cgamma64.o): In function `wgamma_':
cgamma64.F:(.text+0xd1): undefined reference to `s_wsfi'
cgamma64.F:(.text+0xe5): undefined reference to `do_fio'
cgamma64.F:(.text+0xea): undefined reference to `e_wsfi'
...

要查看我的完整错误,请访问我之前的帖子

有人说,这些错误是由不兼容的 f2c 库引起的。所以我找到了一个i386 f2c 库适用于 Ubuntu 14.04。如下所示,我在机器上安装了 f2c:i386,替换了一些以前的软件包。但是运行 时出现了新的错误gfortran -m32 ... -lf2c

gg@gg-VirtualBox:~$ aptitude search f2c
i A f2c                             - FORTRAN 77 to C/C++ translator            
p   f2c:i386                        - FORTRAN 77 to C/C++ translator            
...                                          

gg@gg-VirtualBox:~$ sudo aptitude install f2c:i386
[sudo] password for gg: 
The following NEW packages will be installed:
  binutils:i386{ab} cpp:i386{ab} cpp-4.8:i386{ab} f2c:i386{b} gcc:i386{ab} 
  gcc-4.8:i386{ab} gcc-4.8-base:i386{a} gcc-4.9-base:i386{a} 
  libasan0:i386{a} libatomic1:i386{a} libc6:i386{a} libc6-dev:i386{a} 
  libcloog-isl4:i386{a} libf2c2:i386{ab} libf2c2-dev:i386{ab} 
  libgcc-4.8-dev:i386{a} libgcc1:i386{a} libgmp10:i386{a} libgomp1:i386{a} 
  libisl10:i386{a} libitm1:i386{a} libmpc3:i386{a} libmpfr4:i386{a} 
  libquadmath0:i386{a} linux-libc-dev:i386{a} zlib1g:i386{a} 
The following packages will be upgraded:
  linux-libc-dev 
1 packages upgraded, 26 newly installed, 0 to remove and 114 not upgraded.
Need to get 22.5 MB of archives. After unpacking 74.5 MB will be used.
The following packages have unmet dependencies:
 libf2c2 : Conflicts: libf2c2:i386 but 20090411-2 is to be installed.
 libf2c2:i386 : Conflicts: libf2c2 but 20090411-2 is installed.
 cpp-4.8 : Conflicts: cpp-4.8:i386 but 4.8.2-19ubuntu1 is to be installed.
 cpp-4.8:i386 : Conflicts: cpp-4.8 but 4.8.2-19ubuntu1 is installed.
 binutils : Conflicts: binutils:i386 but 2.24-5ubuntu3 is to be installed.
 binutils:i386 : Conflicts: binutils but 2.24-5ubuntu3 is installed.
 gcc : Conflicts: gcc:i386 but 4:4.8.2-1ubuntu6 is to be installed.
 gcc:i386 : Conflicts: gcc but 4:4.8.2-1ubuntu6 is installed.
 cpp : Conflicts: cpp:i386 but 4:4.8.2-1ubuntu6 is to be installed.
 cpp:i386 : Conflicts: cpp but 4:4.8.2-1ubuntu6 is installed.
 gcc-4.8 : Conflicts: gcc-4.8:i386 but 4.8.2-19ubuntu1 is to be installed.
 gcc-4.8:i386 : Conflicts: gcc-4.8 but 4.8.2-19ubuntu1 is installed.
 f2c : Conflicts: f2c:i386 but 20100827-1 is to be installed.
 f2c:i386 : Conflicts: f2c but 20100827-1 is installed.
 libf2c2-dev : Conflicts: libf2c2-dev:i386 but 20090411-2 is to be installed.
 libf2c2-dev:i386 : Conflicts: libf2c2-dev but 20090411-2 is installed.
The following actions will resolve these dependencies:

      Remove the following packages:                        
1)      f2c                                                 
2)      fort77                                              
3)      libf2c2                                             
4)      libf2c2-dev                                         

      Keep the following packages at their current version: 
5)      binutils:i386 [Not Installed]                       
6)      cpp:i386 [Not Installed]                            
7)      cpp-4.8:i386 [Not Installed]                        
8)      gcc:i386 [Not Installed]                            
9)      gcc-4.8:i386 [Not Installed]                        

      Leave the following dependencies unresolved:          
10)     f2c:i386 recommends gcc:i386                        
11)     libc6-dev:i386 recommends gcc:i386 | c-compiler:i386

Accept this solution? [Y/n/q/?] y
The following NEW packages will be installed:
  f2c:i386 gcc-4.9-base:i386{a} libc6:i386{a} libc6-dev:i386{a} 
  libf2c2:i386{a} libf2c2-dev:i386{a} libgcc1:i386{a} 
  linux-libc-dev:i386{a} 
The following packages will be REMOVED:
  f2c{a} fort77{a} libf2c2{a} libf2c2-dev{a} 
The following packages will be upgraded:
  linux-libc-dev 
The following packages are RECOMMENDED but will NOT be installed:
  bcc:i386 clang-3.3:i386 clang-3.4:i386 clang-3.5:i386 gcc:i386 
  gcc-4.4:i386 gcc-4.6:i386 gcc-4.7:i386 gcc-4.8:i386 tcc:i386 
1 packages upgraded, 8 newly installed, 4 to remove and 114 not upgraded.
Need to get 7,991 kB of archives. After unpacking 21.9 MB will be used.
Do you want to continue? [Y/n/?] y ...
...

现在使用该-lf2c选项时会出现新错误(ading-lm不起作用)。如果没有此选项,错误与以前相同。

gg@gg-VirtualBox:~/Desktop/myfolder$ gfortran -m32 -O -o out10 MBpart1ep0.f -L. -lmathlib -lkernlib -Lcuba -lf2c
/tmp/cc66Jegn.o: In function `MAIN__':
MBpart1ep0.f:(.text+0x82): undefined reference to `cuhre_'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../libf2c.so: undefined reference to `MAIN__'
collect2: error: ld returned 1 exit status

有人知道我该怎么做才能解决这个问题吗?

答案1

我将其MBpart1ep0.f编译为 amd64 二进制文件而不是 i386,因此这可能更容易。

sudo apt-get install gfortran libmathlib2-dev libcuba3-dev

然后我编译了:

gfortran -o out10 MBpart1ep0.f -lmathlib -lcuba

不幸的是,out10文件在调用时立即出现段错误cuhre_。查看代码,问题似乎是该cuhre函数有一个额外的userdata参数。我对 fortran 了解不够,无法弄清楚如何在那里传递一个空参数,但我用以下代码替换了对的调用cuhre

call cuhre(ndim, ncomp, integrand, 0, epsrel, epsabs, flags,
&   mineval, maxeval, key, nregions,
&   neval, fail, integral, error, prob)

0因此,只需在参数后面添加参数即可integrand。使用此更改重建它不会出现段错误,并且实际上会打印出结果:

-0.7044994994694501E-01  0.7023304936781998E-05   0.000000000000000

我不太理解代码,所以我不能说这是否正确。我会说我也在 i386 chroot 中重建以查看它是否有任何区别,我们得到了基本相同的值:

-0.7044994994694533E-01  0.7023304934705608E-05  0.3745918505937418E-16

相关内容