2

I have Ubuntu 14.04 on a 64-bit machine. I would like to run gfortran -m32 for my f77 fortran code that also uses i386 CERN libraries. I downloaded Ubuntu packages cernlib, lib32gfortran-4.8-dev, and gcc-multilib. But I got errors like this when I ran my command:

$ 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'
...

To see my full error, go to my previous post.

As someone suggested, these errors are caused by an incompatible f2c library. So I found that there is an i386 f2c library for Ubuntu 14.04. As shown below, I installed the f2c:i386 on my machine, replacing some previous packages. But then I got new errors when running 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 ...
...

New errors when now using the -lf2c option (ading -lm doesn't have an effect). Without this option, the errors are same as before.

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

Does anyone know what I can do to fix this problem?

1 Answer 1

2

I got the MBpart1ep0.f to compile as an amd64 binary instead of i386, so this might be easier.

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

I then compiled with:

gfortran -o out10 MBpart1ep0.f -lmathlib -lcuba

Unfortunately, the out10 file segfaults immediately with the call to cuhre_. Looking at the code, the problem seems to be that the cuhre function has an extra userdata argument. I don't know enough about fortran to figure out how to pass a null argument there, but instead I replaced the call to cuhre with:

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

So just added the 0 argument after the integrand argument. Rebuilding with this change it doesn't segfault, and actually prints out a result:

-0.7044994994694501E-01  0.7023304936781998E-05   0.000000000000000

I don't really understand the code, so I can't say if this is correct. I will say that I also rebuilt in an i386 chroot to see if it made any difference and we got basically the same value:

-0.7044994994694533E-01  0.7023304934705608E-05  0.3745918505937418E-16
2
  • Hi Jason, thank you SO MUCH! I wish I could give you 50 points for this, but I don't even have enough points to up vote. A follow up question, how did you figure out where the segfault is in the out file? When I just run ./out10, it just says segfault without pointing to the location.
    – Alice
    Sep 11, 2014 at 2:45
  • @Alice I added -g to the gfortran line to enabled debugging symbols and then ran it with gdb ./out10. You can run the app with r and it catches the sigsegv, which told me that it was crashing in a function called by cuhre_, but not why. Installing libcuba3-dbg I could see that the prob argument was wrong, and after looking at the libcuba3 source code, I could see that we had too few arguments. If you were to break on cuhre_ and print out the arguments you could see that they were all off by one after integrand. Sep 11, 2014 at 2:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .