Collect2: ld returned 1 exit status

  • Thread starter Thread starter jpv90
  • Start date Start date
AI Thread Summary
The discussion revolves around troubleshooting a Fortran code error related to undefined references to the 'time_' function. The user is attempting to understand WENO advection code and plans to rewrite it in Matlab or Python. The error indicates a linking issue rather than a compilation problem, suggesting that the linker cannot find the 'time_' function. Recommendations include commenting out the line that calls the TIME function to see if the error persists, and ensuring that all necessary libraries are linked correctly. The discussion highlights the potential need to replace the TIME function with DATE_AND_TIME for compatibility with Fortran 95 or later, and notes possible issues with case sensitivity in function names. Users are encouraged to consult gfortran documentation for linking external libraries and to verify the initialization of variables like char_time.
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!
 
Technology news 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 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.
 
Also char_time doesn't have a value i.e. Isn't initialized. Is that what you're expecting? Does the time function give it a value?
 
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 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 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 jedishrfu
  • #10
A lot of thanks to everyone for your suggestions. I'll try and commenting.
 

Similar threads

Replies
4
Views
2K
Replies
16
Views
6K
Replies
5
Views
10K
Replies
5
Views
5K
Replies
4
Views
7K
Back
Top