Collect2: ld returned 1 exit status

  • Thread starter Thread starter jpv90
  • Start date Start date
Click For Summary
SUMMARY

The discussion centers on a Fortran compilation error indicated by "collect2: ld returned 1 exit status," which arises from an undefined reference to the 'time_' function. The user is advised to ensure that all relevant libraries are linked correctly and to consider using the Fortran 95 standard function DATE_AND_TIME() instead of the obsolete TIME function. Additionally, the importance of checking for case sensitivity in function names is emphasized, as the linker may differentiate between 'TIME_' and 'time_'. The user is encouraged to explore gfortran documentation for linking external libraries.

PREREQUISITES
  • Understanding of Fortran programming, specifically Fortran 95 or later.
  • Familiarity with gfortran compiler and its linking process.
  • Knowledge of library management in programming environments.
  • Basic understanding of function naming conventions and case sensitivity in programming.
NEXT STEPS
  • Research how to link external libraries using gfortran.
  • Learn about the DATE_AND_TIME() function in Fortran for time handling.
  • Investigate common linking errors in gfortran and their solutions.
  • Explore the GNU Compiler Collection (GCC) documentation for detailed linking guidelines.
USEFUL FOR

This discussion is beneficial for Fortran developers, particularly those transitioning from older Fortran standards, as well as programmers troubleshooting linking errors in gfortran.

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 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 16 ·
Replies
16
Views
6K
  • · Replies 5 ·
Replies
5
Views
10K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K