Thursday, 24 November 2011

how to fix "error trying to exec 'f951': execvp: No such file or directory"

error trying to exec 'f951': execvp: No such file or directory
error trying to exec 'cc1': execvp: No such file or directory

I was trying to compile a program today on OS X Lion using gfortran, but to my disappointment I got these errors every time. I am not really familiar with this kind of stuff, so I wasn't sure where to look at first. Even when trying to compile a simple hello_world program.

The internet wasn't very useful either. Google gave me barely anything :(


The solution


First I removed xcode, with the idea to reinstall it later:

sudo /Developer/Library/uninstall-devtools -mode=all

After that I dug into my /usr/local/lib and /usr/bin folders and removed any reference to gcc, gcov, g++, cpp and gfortran, which are all part of the gcc package.

I also removed all references to llvm-* (where * can be gcc, g++, etc). This comes with xcode, not really sure what this is used for. And finally I removed the libgcc/ folder and all libgfortran-related files in /usr/local/lib.

I rebooted for good measure.

Next I got Xcode 4 from the Appstore (for OS X 10.6 and lower, it's available on the Mac Dev Center and installed it. Again I went into my /usr/bin/ and removed the symlink xcode made to their (incomplete, it misses gfortran) gcc.

I downloaded and installed gcc-lion.tar.gz from HPC and installed using:
gunzip gcc-lion.tar.gz sudo tar -xvf gcc-bin.tar -C /

After that, everything seemed to work! There is without doubt a faster way to fix it, but after trying to fix it for a few hours, I'm glad it now works! :)


What else?


If gcc gives an error that looks something like this:

ld: symbol(s) not found for architecture x86_64 collect2:
ld returned 1 exit status,

an explanation can be found here. Basically, the lstdc++ parameter has to be given, so it uses the correct library. Alternativey, g++ or clang++ can be used directly.


Useful links:


http://www.webmo.net/support/fortran_osx.html
http://hpc.sourceforge.net/

6 comments:

  1. I got into this situation by upgrading from lion to moutain lion, installing xcode 4.3, and installing gfortran via homebrew. This blog was interesting, but was able to get out of my dilemma by:

    1) uninstall gfotran homebrew
    2) remove /usr/bin/gfortran (seemingly still present...)
    3) from http://hpc.sourceforge.net/ install gcc-mlion.tar.gz (4.8)

    After this it seems to work. In fact, I had done 3) before 2), and it still didn't work, but the /usr/bin/local/ version of gfortran did work, which led me to that link. YMMV

    ReplyDelete
  2. I had this same problem.. after downloading the gcc-mlion jar above, I didn't copy ALL of the files from the binary distro (I just copied over the gfortran)... the f951 lives in the /libexec dir.. Once I copied all the files over, it worked just fine.. No need to uninstall/re-install the world

    ReplyDelete
  3. Thank you SO MUCH. I tried for 2 hours to get gfortran working. I've had OS X on my computer since about 5 versions ago (panther?). I always had various versions of fortran floating around. Upgrade from snow leopard to mountain lion broke everything.

    I note that now to download XCODE (4.6.1 at this time) you do it from the Apple Store. It is uninstalled by deleting the file inside /Applications. Also, you must additionally install the XCODE command-line tools inside the Preferences menu of XCODE (go into Downloads there, there will be an option).

    I find it kind of silly to have to download ~ 2GB of stuff just to get fortran working, but whatever it works!

    ReplyDelete
  4. excuse me for my maybe idiot question but after these steps how do i run fortran???

    ReplyDelete
  5. its not working still prompting same error for fedora 24

    ReplyDelete