Collect2: ld returned 1 exit status

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

Discussion Overview

The discussion revolves around a compilation and linking error encountered while running a Fortran program related to WENO advection code. Participants explore potential causes and solutions for the error message "collect2: ld returned 1 exit status," focusing on issues with undefined references and library linking.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Exploratory

Main Points Raised

  • One participant identifies the error as a linking problem rather than a compilation issue, suggesting that relevant libraries may not be found by the linker.
  • Another participant proposes commenting out the line that calls the TIME function to check if the error persists, indicating that the function may not be properly linked.
  • There is a suggestion to use gfortran and to search for documentation on linking external libraries, as well as specific error messages related to gfortran.
  • A participant notes that the variable char_time may not be initialized, questioning whether the TIME function assigns it a value.
  • Concerns are raised about the portability of the TIME function, with a recommendation to use DATE_AND_TIME() instead, as it may be more compatible with Fortran 95 and later.
  • Another participant mentions potential issues with capitalization in function names, suggesting that the linker may be looking for TIME_ instead of time_.

Areas of Agreement / Disagreement

Participants generally agree that the error is related to linking issues and the undefined reference to the TIME function. However, there are multiple suggestions regarding how to resolve the issue, including changing the function used and addressing potential capitalization problems, indicating that the discussion remains unresolved.

Contextual Notes

Participants express uncertainty about the initialization of variables and the portability of certain Fortran functions, which may affect the program's execution. There is also a lack of consensus on the best approach to resolve the linking issue.

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