/usr/bin/ld file missing in snow leopard - compilation

I am trying to compile a fortran program using gfortran installed on Mac OSX, and I get the following error:
collect2: cannot find 'ld'
And when I try
ls -l /usr/bin/ld
I get
ls: /usr/bin/ld: No such file or directory
Can someone tell me how I can install this file?

ld comes with XCode Tools, which you need to install separately from XCode:
http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/ld.1.html

Related

Can't compile fortran on MacOS Monterey: ld: unsupported tapi file type '!tapi-tbd' in YAML file

I am facing an error whenever I try to compile fortran code:
% gfortran Testing_Fortran.f90 -o Testing_Fortran
ld: unsupported tapi file type '!tapi-tbd' in YAML file '/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/lib/libSystem.tbd' for architecture x86_64 collect2: error: ld returned 1 exit status
Looking at similar issues through the internet, the most common solutions I've found are to downgrade the XCode command line tools, and to reinstall gcc, but none of this worked.
I tried CLTools 14.1 and 13.4, and I am installing gcc via homebrew. The gfortran version is 12.2.0. I'm on MacOS Monterey 12.6.
Any ideas? Thanks in advance.
It's likely that your ld isn't the latest system linker: both on this help ticket and with a coworker the problem was that ld pointed to one from Anaconda. If your $PATH is set up so that Anaconda's ld has higher preference over the system linker, this will explain it:
$ which -a ld
/blah/anaconda3/bin/ld
/usr/bin/ld
If that's the case, reorder your PATH to put anaconda's directory after /usr/bin. Then, which ld should point to the system ld, and you should be good to go.

gfortran is not working on Mac OS X 10.9 (Mavericks)

Recently, I updated my OS X to 10.9 (Mavericks); unfortunately, gfortran stops working although I updated Xcode command line to 5.1.1 for OS X Mavericks. Similar question has been asked sometime ago, here, but I don't think so the issue is sorted out.
here is what I did:
first I removed the existing gfortran
bash-3.2$ sudo rm -r /usr/local/gfortran /usr/local/bin/gfortran
Then I downloaded gfortran-4.9-bin.tar, and unzip it and installed successfully
bash-3.2$ gunzip gfortran-4.9-bin.tar
bash-3.2$ sudo tar xvf gfortran-4.9-bin.tar -C /
bash-3.2$ which gfortran
/usr/local/bin/gfortran
but when I start running my codes , I got the following errors, e.g.
bash-3.2$ gfortran boolean1.f90
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
I would be immensely grateful if anyone could guide me to solve this problem.
Just for the record. I suggest to install gfortran from packages that are available from here:
https://gcc.gnu.org/wiki/GFortran
macOS installer can be found here: http://coudert.name/software/gfortran-6.3-Sierra.dmg
Just install most recent release (using dmg file) and everything should be fine
! fort_sample.f90
program main
write (*,*) 'Hello'
stop
end
Compilation and execution goes smooth
> gfortran -o fort_sample fort_sample.f90
> ./fort_sample
Hello

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

I'm trying to compile a code found on the internet. Actually I'm trying to compile the code found at http://www.cs.berkeley.edu/~fowlkes/BSE/.
I tried to install gfortran and all the other libraries that are needed for compiling it in my MAC. But when I run the command make I get the following error:
$ make
(cd trlan && make -f Makefile.gcc)
gfortran -O3 -ffixed-line-length-132 -c dsort2.f
gfortran: error trying to exec 'f951': execvp: No such file or directory
make[1]: *** [dsort2.o] Error 1
make: *** [trlan/libtrlan.a] Error 2
I believed that the error is related to the version of my c++ compiler, that is not compatible with gfortran.
When I run the command gcc --version:
$ gcc --version
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
And when I run the command gfortran --version:
$ gfortran --version
GNU Fortran (GCC) 4.8.0 20120930 (experimental)
The Makefile under the directory that I'm running the command make is here: https://www.dropbox.com/s/q7mxvhnqg62ioum/Makefile.gcc
The Makefile under the directory trlan is here: https://www.dropbox.com/s/jydwpkg3f1upbgf/Makefile.gcc
Anyone has an idea of how to solve this problem or how to find tools that can help me solve it?
I'm trying this:
http://eftrunk.blogspot.com/2011/11/how-to-fix-error-trying-to-exec-f951.html
The simplest solution I found (perhaps not cleanest), is to statically link f951 in the path to the binary of gfortran:
find /usr/local/ -name f951
which for me returned:
/usr/local/gfortran/libexec/gcc/x86_64-apple-darwin11/4.6.2/f951
/usr/local/gfortran/libexec/gcc/x86_64-apple-darwin14/5.1.0/f951
so I put a link to the one that fits my system most closely in /usr/local/bin:
sudo ln -s /usr/local/gfortran/libexec/gcc/x86_64-apple-darwin14/5.1.0/f951 /usr/local/bin/.
And now gfortran works again. No need to uninstall XCode or any other exaggerated workload.
The answer can be found in the following website:
http://eftrunk.blogspot.com/2011/11/how-to-fix-error-trying-to-exec-f951.html
Basically it's necessary to delete Xcode, reinstall gcc and gfortran using http://hpc.sourceforge.net/ and then reinstall Xcode.

gcc: error trying to exec 'as': execvp: No such file or directory

I was trying to install gcc and gfortran on my intel mac with mountain lion and keep getting the above error when trying to compile the fortran file. gcc doesn't seem to work either with c programs. This is the error I get with my c program:
test.c:1:19: fatal error: stdio.h: No such file or directory
I tried typing this into terminal:
export PATH=${PATH}:/usr/local/bin
but that did not work. I added gcc and gfortran to /usr/local/bin instead of /usr/bin. I downloaded the compilers through hpc. The files had the given directory structure:
/usr/local/bin: contained gcc and gfortran along with other compilers
/uer/local/include/...
/usr/local/lib/...
etc...
I pretty much just copied and pasted all the files directly over to the exact same path directories on my computer and ran the export command. That is all I have done.
You probably need either odcctools (as provided by macports) or XCode (which contains the Mac "binutils", and the Clang compiler, GCC was discontinued).

changing search-dirs for $ sudo gcc

On OS X I'm trying to install the zlib prerequisite for haskell's Cabal. I get this error:
$ sudo ./Setup build
Preprocessing library zlib-0.5.0.0…
ld: library not found for -lgmp
collect2: ld returned 1 exit status
linking dist/build/Codec/Compression/Zlib/Stream_hsc_make.o failed
command was: /usr/bin/gcc -lz -L/sw/lib/ghc-6.8.3/lib/bytestring-0.9.0.1.1 -L/sw/lib/ghc-6.8.3/lib/array-0.1.0.0 -L/sw/lib/ghc-6.8.3/lib/base-3.0.2.0 -L/sw/lib/ghc-6.8.3 -lm -lgmp -ldl dist/build/Codec/Compression/Zlib/Stream_hsc_make.o -o dist/build/Codec/Compression/Zlib/Stream_hsc_make
The library -lgmp is found in /sw/lib, so I can run that command ("/usr/bin/gcc ...") successfully if I manually add -L/sw/lib. The problem is that sudo doesn't know about /sw/lib. Behold:
$ gcc -print-search-dirs | grep sw
libraries: =/lib/i686-apple-darwin9/4.0.1/:/lib/:/usr/lib/i686-apple-darwin9/4.0.1/:/usr/lib/:./i686-apple-darwin9/4.0.1/:./:/sw/lib/i686-apple-darwin9/4.0.1/:/sw/lib/:/usr/lib/gcc/i686-apple-darwin9/4.0.1/:/usr/lib/gcc/i686-apple-darwin9/4.0.1/:/usr/lib/gcc/i686-apple-darwin9/4.0.1/../../../../i686-apple-darwin9/lib/i686-apple-darwin9/4.0.1/:/usr/lib/gcc/i686-apple-darwin9/4.0.1/../../../../i686-apple-darwin9/lib/:/usr/lib/gcc/i686-apple-darwin9/4.0.1/../../../i686-apple-darwin9/4.0.1/:/usr/lib/gcc/i686-apple-darwin9/4.0.1/../../../
$ sudo gcc -print-search-dirs | grep sw
$
How do I tell the sudo version of gcc to look in /sw/lib for libraries? Do I add an environment variable on root's .bash_profile? If so, which one?
UPDATE:
There’s probably a more proper way to do this, but here’s what worked. I created a bash script with this in it:
#!/bin/sh
export LIBRARY_PATH=/sw/lib:$LIBRARY_PATH
./Setup build
And then I ran
$ sudo ./script.sh
That compiled zlib without complaining - hooray! Unfortunately cabal-install is still giving me the error:
$ ./Setup configure
Configuring cabal-install-0.6.2…
Setup: At least the following dependencies are missing:
zlib >=0.4 && <0.6
So I went back to the cabal-install dir (which is what I'm trying to do in the first place), and ran...
$ ./bootstrap.sh
...and that installed everything as expected.
Why you use sudo ever? You should not compile as super user. Compile as normal user and install as super user.
Try setting LDFLAGS=-L/sw/lib.
GHC now comes with an installer for OS X (Leopard, not sure about Tiger). The only issue is that if you use macports or fink, these will probably not see that you have GHC installed and try to install their own version of it.

Resources