Collect2: ld returned 1 exit status

  • Thread starter Thread starter jpv90
  • Start date Start date
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
9 replies · 7K views
jpv90
Messages
3
Reaction score
0
Hi, I am learner in Fortran, so my purpose is to understand the WENO advection code, and following write a new code in Matlab or Python. I have got the Fortran code, but when running it, showing the follow error:
In the function 'MAIN__'
code_WENO.f: (text+0x804): reference 'time_' undefined
code_WENO.f: (text+0x2b94): reference 'time_' undefined
collect2: ld returned 1 exit status

I think the error could be in this code's part:

Fortran:
character*8 char_time,yc
open(3,file='1d_single.time')
open(101,file='1.err')
call TIME(char_time)
write(*,*) 'time' ,char_time
write(3,*) 'time: ', char_time
pi=4.0*atan(1.0)
cfl=0.4
tf=1.5/pi
eps=1.e-8
istop=0
md=4
n=80
dx=2.0/n

My OS is Ubuntu 14.

Thanks!
 
on Phys.org
jpv90 said:
collect2: ld returned 1 exit status
I can only look at this briefly now, but it does not indicate a compilation problem, but rather a linking problem. Check to make sure that all relevant libraries can be found by the linker.
 
Thank you for your answer Krylov, but how I know that? could you give me a example or a book, please. Excuse me.
 
I agree with Krylov the error indicates that the loader i.e. 'ld' had a problem finding the time_ function which you are calling in your program. To test this out you could comment out that line and rerun to see if the error disappears, if so then you need to find out how to load the library containing the time function.
 
  • Like
Likes   Reactions: FactChecker
I suppose you use gfortran? Do some googling for examples of linking with external libraries using gfortran, or perhaps google directly for "gfortran" and the error "collect2: ld returned 1 exit status" which is probably well-documented in the gcc (= GNU compiler collection, of which gfortran is part) documentation.
 
The subroutine TIME is being called and it looks like it is supposed to return the time in char_time. But the linker can not find a definition of the function TIME. (The underscores, like in MAIN_ and TIME_, are often added to names that the linker is supposed be able to find somewhere else.)
 
  • Like
Likes   Reactions: jedishrfu
TIME may be obsolete, to be sure, I don't think it was ever very portable. Fortran 95 or later, you need to use DATE_AND_TIME()
 
  • Like
Likes   Reactions: jedishrfu
If changing to DATE_AND_TIME doesn't work, there may be a problem with capitalization. It is peculiar that the error message talks about MAIN_ in all caps and about time_ in all lower case. You may need to use a compiler or linker option to tell it that you are looking for TIME_ and not time_.
 
  • Like
Likes   Reactions: jedishrfu
A lot of thanks to everyone for your suggestions. I'll try and commenting.