. Advertisement .
..3..
. Advertisement .
..4..
I got this error ”in function `_start’: (.text+0x20): undefined reference to `main”’ when I run my program.
My program:
Program InvertMultiply
implicit none
integer (kind=4),parameter :: nx=3
integer (kind=4) :: ipiv(nx)
integer (kind=4) :: info,i,j
real (kind=8) :: A(nx,nx), B(nx,nx), C(nx,nx), work(nx)
real (kind=8) :: alpha,beta
external DGEMM
external DGETRF
external DGETRI
A=reshape((/1,-1,-1,0,1,0,0,0,1/),(/3,3/));
B=A ! copy of A
call DGETRF(nx, nx, B, nx, ipiv, info)
call DGETRI(nx, B, nx, ipiv, work, nx, info)
alpha=1
beta=0
CALL DGEMM('N','N',nx,nx,nx,alpha,A,nx,B,nx,beta,C,nx)
print *,'A*Ainv'
do i=1,nx
write(*,fmt="(6(1x,f4.1))")C(i,:)
end do
! should be diagonal
End Program InvertMultiply
It checks for the availability of LAPACK procedures. I am able to link and compile for:
gfortran InvertMultiply.f90 -llapack -lblas
a.out
is generated and provides the correct answer.
Nevertheless, if I divide the compilation link into 2 steps:
gfortran -c InvertMultiply.f90
gfortran -o InvertMultiply.o -llapack -lblas
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
I don’t know where’s wrong and how to fix? Can someone help me?
The cause: This error happens because
-o
specifies the output name, and not the objects… So-o InvertMultiply.o
specifies the output to beInvertMultiply.o
. There are only the libraries left, and there is nomain
in them.Solution: You can fix this error by adding an output file (or leave out the
-o
completely in which case the executable will likely bea.out
):