Collect2: ld returned 1 exit status

  • Thread starter jpv90
  • Start date
In summary, the code for the WENO advection code does not work because the time function was not found by the linker.
  • #1
jpv90
3
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
  • #2
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.
 
  • #3
Thank you for your answer Krylov, but how I know that? could you give me a example or a book, please. Excuse me.
 
  • #4
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
  • #5
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.
 
  • #6
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?
 
  • #7
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
  • #8
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
  • #9
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.
 

What is "Collect2: ld returned 1 exit status"?

"Collect2: ld returned 1 exit status" is an error message that occurs during the process of linking object files to create an executable program. It indicates that the linker, which is responsible for connecting different parts of a program together, encountered an error and was unable to complete the linking process.

What does the number 1 in "ld returned 1 exit status" mean?

The number 1 in "ld returned 1 exit status" refers to the error code returned by the linker. In this case, the error code 1 indicates a generic error, meaning that the linker was unable to complete its task due to an unspecified issue.

Why am I getting a "Collect2: ld returned 1 exit status" error?

There could be several reasons why you are getting this error. Some common causes include missing or incorrect libraries, incompatible object files, and syntax errors in the source code. It is important to carefully check your code and make sure all necessary libraries are included and properly linked.

How can I fix a "Collect2: ld returned 1 exit status" error?

The first step in fixing this error is to identify the specific cause. Check your code for any syntax errors and make sure you have included all necessary libraries. If the error persists, try using a different version of the linker or updating your compiler. It may also be helpful to search online forums or ask for assistance from more experienced programmers.

Is a "Collect2: ld returned 1 exit status" error always fixable?

In most cases, this error can be fixed by identifying and addressing the underlying cause. However, there may be rare instances where the error is caused by a bug in the compiler or linker, in which case it may not be immediately fixable. If you are unable to resolve the error, it may be necessary to seek help from the developers of the compiler or linker.

Similar threads

  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
4
Views
630
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
16
Views
5K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
5
Views
9K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
2
Views
4K
Back
Top