0

I have been trying to run this model, written some decades ago by someone else. I've built the libraries, but when I try to actually run the program, I get the following error:

f77   -o mimics1.5  ../source/*.o  trunk_hght_f.f 
    trunk_hght_f.f:
       trunk_hght_func:
    Undefined symbols for architecture x86_64:
      "MAIN__", referenced from:
         -u command line option
         (maybe you meant: _MAIN__)
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

I am on MacOSX 10.11, and which f77 gives /usr/local/bin/f77 and f77 -v gives back:

Cynthias-MacBook-Pro-2:input_dir cynthiag$ f77 -v    
/usr/local/bin/f77 script based on f2c:
    f2c (Fortran to C Translator) version 20100827.

Should f77 be in /usr/bin/instead?

ld seems to be the problem, so I followed instruction from HERE to try to solve it, but it looks like my XCode is up to date, that my libraries are built and linked (as far as I can tell), and I even reinstalled binutils to make sure ld was in teh right place, but no success. which ld gives : /usr/bin/ld and ld -v gives:

Cynthias-MacBook-Pro-2:input_dir cynthiag$ ld -v
@(#)PROGRAM:ld  PROJECT:ld64-264.3.102
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em (tvOS)
LTO support using: LLVM version 7.3.0

I am new to fortran, so I probably messed up when setting up f77, but I've been stuck on this problem for a few days now, so any help would be greatly appreciated!

Cynthia GS
  • 522
  • 4
  • 20
  • If your source code has no PROGRAM procedure (prior to f77, procedure with no FUNCTION or SUBROUTINE heading) you will need to fix that. Next, it should be easier to use gfortran rather than the f77 translator of 2 decades ago. – tim18 May 16 '16 at 00:30
  • @tim18: Not completely sure what you mean by the first part of your comment, but there is a `runit` file that the README tells me to run. That's what giving me this error. I also switched to using gfortran, exact same error. – Cynthia GS May 16 '16 at 02:28
  • @roygvib: I edited the question with the info on `gfortran`. A simple `hello world` program works fine. When running the line you suggested, I get a new error type regarding a bunch of duplicates and ending in: `ld: 19 duplicate symbols for architecture x86_64 collect2: error: ld returned 1 exit status`... – Cynthia GS May 16 '16 at 04:12
  • @roygvib: I have changed all the calls to `f77` into `gfortran` and I made an alias in my bash profile. The duplicate are actually weird files : `duplicate symbol _set_flag_ in: /var/folders/n0/0df9sk4934q632rhr5dqcv0h0000gn/T//ccHPHth6.o /var/folders/n0/0df9sk4934q632rhr5dqcv0h0000gn/T//cc0ZazUC.o` They are not part of my library, I just did a clean install of the model, and same problem. – Cynthia GS May 16 '16 at 14:24
  • So I think it it just compiled! The error about the duplicate was from the line you had suggested, but running the actual line of code seem to have done the trick: `gfortran -o mimics1.5 ../source/*.o trunk_hght_f.f`. Now unfortunately, I'm not actually sure what got it to work... I think it was clean install + careful change of all the f77 mentions + adding some `./` in front of the executables. I'm a bit frustrated, because I'm not completely sure what did it in the end... – Cynthia GS May 16 '16 at 15:24
  • OK, sorry, then I believe you can delete messages about duplicates etc from the Question; instead, adding info about (1) what error message you got precisely with gfortran after your clean install, and (2) whether you successfully generated an excecutable (mimics1.5). Also, is this page related ? ftp://198.22.133.103/rbryant/MIMICS_INFO/READMEmimics.txt The last part seems to indicate that you need to exclude some files from ../source/. – roygvib May 16 '16 at 15:57
  • @roygvib: Yes, that's it. I was actually just at section 1.2, in the testing phase. It did generate the executable, which itself runs great and generates the output files expected. I will clean up the question later this afternoon. – Cynthia GS May 16 '16 at 16:41
  • Though not sure if this is the latest version, I have downloaded the package called MIMICS-1.5a from [here](ftp://198.22.133.103/rbryant/MIMICS_compiled/) (actually, I used `wget -r ftp://198.22.133.103/rbryant/MIMICS_compiled/`). Then going to the directory "source" and modifying Makefile (f77 -> gfortran), remove all *.o and do "make". Next, go to the directory "input_dir", modify Makefile (f77 -> gfortran), remove "mimics1.5", then "make". This will generate a new excutable there. By typing "./mimics1.5", I got some output data (both on Linux and MacOSX10.9). Maybe worth trying... – roygvib May 16 '16 at 16:45
  • @roygvib: Great! That's about exactly what I did when I got it to work, good to see that it's reproducible. I'm curious to hear how you found it so easily, the U of Mich seem to be pretty protective and I had to contact them to get it! – Cynthia GS May 16 '16 at 17:01
  • @roygvib: Thanks a lot for your help and your patience. I would like to gave you some points for your help if you want to try to formulate an official answer on using f77 VS gfortran. – Cynthia GS May 16 '16 at 17:11
  • Glad if it works :) Actually you can google for the file name trunk_hght_f.f and the second hit is the above Michigan site (though it seems not public...). Also, you can get much info by googling for error messages you get. As for the answer, could you please make an answer by yourself, explaining what was the problem (e.g., there was no main program like mimics_1_5a.f, or other f77 vs gfortran installation issues) because you are the most familiar with the situation... :) Thanks – roygvib May 16 '16 at 17:17

1 Answers1

0

In the end, it seem like the solution for me was just to use gfortran instead of f77. This involved carefully switching all the mentions to f77 in the model (i.e. in all the Makefiles) and replacing them by gfortran.

A clean install of the libraries was then necessary, since apparently a library compiled in f77 will not be compatible with gfortran.

Finally, the model was calling on some executable without ./ which caused the model to failed.

Unfortunately, I can't give an explanation as to why f77 was failing, but gfortran was a lot easier to set up than f77/f2c and worked great, so it's probably the way to go.

Cynthia GS
  • 522
  • 4
  • 20