What is the meaning of 'ld: library not found for -lm' - macos

I'm a beginner at Fortran code. I install gfortran from the homebrew to my apple silicon mac. The path show in the terminal when I type which fortran is /opt/homebrew/bin/gfortran
I try to use bash shell to run a 'hello world' fortran file on the Desktop (.f90 file). I typed the following command in the terminal. gfortran prog01_01.f90. But it does not work. The error says: ld: library not found for -lm and collect2: error: ld returned 1 exit status. I have no idea how to deal with this problem.
Can anyone please help me this out?

This means that the compiler cannot find the basic mathematical library libm. It should normally be included in your GLIBC or other standard C library installation and be available in the appropriate library directories and I would expect that your package manager would complain that something is missing.
Anyway, you simply have to fix your software installation, we cannot tell you more without details about your system and your software packages. You can try to install GLIBC if you did not install it yet.

Related

I installed Nim without any problem, but it gives me this error, what should I do?

I install Nim Lang but it not works. I get this errors, how can i fix? (I have completed the setup.)
Error: invocation of external compiler program failed. Sistem belirtilen dosayayi bulamiyor.
Additional info: "Requested command not found: \'gcc.exe -c -w -fmax-errors=3 -mno-ms-bitfields -I\"C:\\Program Files\\Nim Language\\lib\" -IC:\\Users\\SyTax\\Desktop -o C:\\Users\\Sytax\Desktop -o C:\\Users\\SyTax\\nimcache\\name_d\\stdlib_io.nim.c.o C:\\Users\\SyTax\\nimcache\\name_d\\stdlib_io.nim.c\'. OS error:" 2
Error;
enter image description here
Probably you only installed the first package from Nim's windows installation page. Note that there are other dependencies mentioned on that page. You may also need:
MingW compiler dependency, installed with finish.exe.
DLLs available on your system, like PCRE or OpenSSL, also available for download.
Alternatively you could try installing Nim using Scoop, which seems to be able to install both Nim and the required compiler.
The Nim compiler creates C code, so to compile your code to binary and run, you should install a C compiler. The default is GCC. In linux and mac, it comes with the system, so I am assuming you are using windows.
I am not a Windos user, but AFAIK you neet to install mingw amd gcc
http://www.codebind.com/cprogramming/install-mingw-windows-10-gcc/
http://mingw.org/

Error while trying trying to run make command

I am trying to install a program and when I run make or make -f Makefile (following the installation instructions) I get the following output:
g77 -O5 -Wall -c prep_output.f -o prep_output.o
dyld: Symbol not found: ___keymgr_global
Referenced from: /usr/local/bin/g77
Expected in: /usr/lib/libSystem.B.dylib
make: *** [prep_output.o] Abort trap: 6
I am working on a macOS Mojave 10.14.6. Following some other proposed solutions in similar problems, I've already installed Command line tools in my Xcode but that didn't do the trick. Any suggestions please??
Thanks in advance
EDIT:
I got rid of g77 and installed a compatible version of gcc (gcc8) through MacPorts. After running the make command I get the following:
g77 -O5 -Wall -c prep_output.f -o prep_output.o
make: g77: No such file or directory
make: *** [prep_output.o] Error 1
So I guess the program still needs the g77 setup? This is the program btw ([http://www.cfht.hawaii.edu/~arnouts/LEPHARE/install.html]). Is there a way to rely to the gfortran compiler for building the program?
Thanks in advance
P.S. I noticed that when I install g77 I get the following error:
x usr/local/: Can't set user=0/group=0 for usr/local`
`tar: Error exit delayed from previous errors.
However it still installs g77..
The error message indicates that your installation of g77 is broken. This has nothing to do with make or the particular project you're trying to build, except inasmuch as the project is trying to use g77 in the first place. That is a bit surprising, actually, since g77 has been obsolete for years (gfortran is the current GNU Fortran compiler), but I'm uncertain what exactly to expect from XCode in this area.
On the other hand, since the full path to the binary is /usr/local/bin/g77, I'm further inclined to think that you're not using XCode for this at all. Possibly you've dumped a g77 built on some other system into your /usr/local/bin, and it's not compatible with your Mojave system.
Your best bet is probably to
Get rid of your broken g77 installation.
Install Fink or MacPorts, or a similar project.
Install the Fink / MacPorts / whatever package for gfortran (maybe gcc-gfortran or similar in some of those) to get a working Fortran compiler.
Rely on that compiler to build your project.

dyld: Library not loaded: #rpath/libgfortran.3.dylib

I am trying to learn Fortran programming language, as a test I wrote a simple program like this:
!Fortran Program
program first
print *, "Hello World"
end program first
Then I threw this code file in to mac terminal and run gfortran first.f95 which then gave me an output of a.out as expected.
However, when I try to run the output in terminal by navigating into the output directory and typing ./a.out. It gave me this error output:
dyld: Library not loaded: #rpath/libgfortran.3.dylib
Referenced from: /Users/liang/Desktop/Programs/Fortran/Test/a.out
Reason: image not found
liang is my username.
I had the same problem, and my problem was caused because the library was not in default path and instead "anaconda" got in the path so that's why the compiler could not load it. I am a pure amateur user so I may explain not accurate in terms of technical words.
What I did was, I uninstalled my anaconda and deleted the folder in my Mac. Installed gcc "brew install gcc" again, and it worked! and then after, I installed my anaconda again, so now everything seemingly is ok.
My situation
I am also just learning, and I had a similar error message after compiling MUMPS library (http://mumps-solver.org).
I compiled the sequential version of MUMPS manually after brew installing the dependencies. When I ran the test examples, I got the same error message that libgfortran.3.dylib could not be loaded.
My brew gnu compiler is gcc version 9 and it is invoked by gcc-9, g++-9 and gfortran-9 (for C, C++ and Fortran respectively). Meanwhile gcc, g++ and gfortran invoke the compilers installed by anaconda.
How I solve it
I recompiled MUMPS using gcc-9 and gfortran-9 instead of gcc-9 and gfortran, and now everything works.

Linker Error PPC

I'm trying to compile a c++11 code under a IBook G4.
I'm using a g++-4.9 installed with brew
However, I get stuck with this error:
/usr/bin/ld: can't locate file for: -lcrt0.o
Found nothing in the net about crt. Maybe, someone has better experience dealing with dinosaurs..
Frustration of having a compiler able to run on multiple architectures with the flip of a command line switch. Use -arch and specify either native or target cpu.

ld: library not found for -lgsl

I'm working in OSX and I'm attempting to run a make file and when I try I get the following:
ld: library not found for -lgsl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [harm] Error 1
Earlier I found out the I needed to get the gsl library and I used mac ports and typed:
sudo port install gsl
into my command line window and it seemed to isntall okay. Is the missing lgsl not configured correctly or does it not come with gsl? I tried googling lgsl but didn't get much. I've only been at programming a few days and I don't know if I was supposed to set a path, or even really how to do that.
Thanks for any help you guys could offer.
I just wanted to say that I had the exact problem on OSX. Rather than setting an environment variable, I used an additional compiler flag -L/opt/local/lib, which then lets one use -lgsl. I reference this answer.
I got the same issue and here is how I fixed it:
export LIBRARY_PATH=/usr/local/Cellar/gsl/1.16/lib/
I had previously installed gsl using:
brew install gsl
You need to add the path for where the macports installed the gsl library to your LD_LIBRARY_PATH environment variable (or most likely into the build script environment). I believe macports stores things in /opt/local/lib

Resources