What causes undefined reference errors in gfortran compilation?

  • Context: Fortran 
  • Thread starter Thread starter SAks
  • Start date Start date
  • Tags Tags
    Gfortran
Click For Summary
SUMMARY

The forum discussion centers on resolving undefined reference errors encountered during gfortran compilation, specifically when linking the BLAS library. The error message indicates that the linker cannot find the BLAS library, suggesting it may not be installed or is located in a non-standard directory. Users are advised to specify the library path using the -L option in the gfortran command. Additionally, a subsequent error related to an undefined reference to `MAIN__` indicates that the main program entry point is not correctly defined in the Fortran source code.

PREREQUISITES
  • Basic understanding of Fortran programming
  • Familiarity with gfortran compiler usage
  • Knowledge of linking libraries in Unix-like operating systems
  • Experience with troubleshooting compilation errors
NEXT STEPS
  • Install the BLAS library on your system
  • Learn how to use the gfortran linker options effectively
  • Understand the structure of Fortran programs, particularly the main program entry point
  • Explore troubleshooting techniques for undefined reference errors in Fortran
USEFUL FOR

This discussion is beneficial for novice Fortran programmers, developers compiling scientific computing applications, and anyone encountering linking issues with gfortran and external libraries.

SAks
Messages
6
Reaction score
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
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.
 
@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
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 9 ·
Replies
9
Views
9K
  • · Replies 5 ·
Replies
5
Views
10K
  • · Replies 16 ·
Replies
16
Views
6K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 3 ·
Replies
3
Views
12K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 9 ·
Replies
9
Views
10K