What causes undefined reference errors in gfortran compilation?

  • Fortran
  • Thread starter SAks
  • Start date
  • Tags
    Gfortran
In summary, the conversation is about a user who is new to Fortran and is having trouble compiling linpack due to an error with the 'blas' library. They are advised to check if the library is installed and if not, to specify the full directory path for the compiler to search for it. However, after doing so, a new error with an undefined reference is encountered.
  • #1
SAks
6
0
Hi friends!
I am a complete newbie to fortran..
I've been trying to compile linpack but keep getting following error..

[SAks@localhost Desktop]$ gfortran schdc.f -lblas
/usr/bin/ld: cannot find -lblas
collect2: ld returned 1 exit status


please advise..

Thanks in advance
 
Technology news on Phys.org
  • #2
It means that the 'blas' library either is not installed, or is not in the location where the compiler (actually the linker) expects to find it.

If that library is in a non-standard location, e.g. /foo/bar/blas.a or /foo/bar/blas.dylib or whatever filename extension your OS uses for libraries, then you can tell the linker to search the directory /foo/bar for libraries, in addition to wherever it already searches:

gfortran schdc.f -L/foo/bar -lblas

You might have to add a slash: -L/foo/bar/ (it's been a long time since I had to do this)

The main thing is to give the full directory path.
 
  • #3
@jtbell
thanks for responding..
I did give the whole path, now some new problem..
this is what i get..

[SAks@localhost Desktop]$ gfortran schdc.f -L/home/SAks/Desktop -lblas
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgfortranbegin.a(fmain.o): In function `main':
(.text+0x26): undefined reference to `MAIN__'
collect2: ld returned 1 exit status
 

FAQ: What causes undefined reference errors in gfortran compilation?

What is Gfortran?

Gfortran is a free and open-source compiler for the Fortran programming language. It is widely used in scientific computing and is available on multiple operating systems.

What are compilation glitches?

Compilation glitches are errors that occur during the process of translating human-written code into machine-readable instructions. These errors can prevent a program from running correctly or at all.

Why do Gfortran compilation glitches occur?

Gfortran compilation glitches can occur due to a variety of reasons, including syntax errors, missing or outdated libraries, or incompatible code. They can also be caused by bugs in the compiler itself.

How can I troubleshoot Gfortran compilation glitches?

To troubleshoot Gfortran compilation glitches, you can start by checking for any syntax errors in your code. If your code is error-free, then you can try updating your libraries or checking for any compatibility issues. You can also consult online resources or forums for help from other users.

Can I prevent Gfortran compilation glitches?

While it is not possible to completely prevent Gfortran compilation glitches, you can minimize the chances of encountering them by writing clean and error-free code, keeping your libraries up to date, and using best practices for coding in Fortran.

Similar threads

Replies
2
Views
2K
Replies
5
Views
1K
Replies
6
Views
1K
Replies
9
Views
8K
Replies
5
Views
10K
Replies
16
Views
6K
Replies
4
Views
6K
Replies
4
Views
12K
Replies
6
Views
2K
Replies
9
Views
9K
Back
Top