Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Collect2: ld returned 1 exit status

  1. Nov 19, 2015 #1
    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:

    Code (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!!
     
  2. jcsd
  3. Nov 19, 2015 #2

    Krylov

    User Avatar
    Science Advisor
    Education Advisor

    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.
     
  4. Nov 19, 2015 #3
    Thank you for your answer Krylov, but how I know that? could you give me a example or a book, please. Excuse me.
     
  5. Nov 19, 2015 #4

    jedishrfu

    Staff: Mentor

    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.
     
  6. Nov 19, 2015 #5

    Krylov

    User Avatar
    Science Advisor
    Education Advisor

    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.
     
  7. Nov 19, 2015 #6

    jedishrfu

    Staff: Mentor

    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?
     
  8. Nov 19, 2015 #7

    FactChecker

    User Avatar
    Science Advisor
    Gold Member

    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.)
     
  9. Nov 19, 2015 #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()
     
  10. Nov 19, 2015 #9

    FactChecker

    User Avatar
    Science Advisor
    Gold Member

    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_.
     
  11. Nov 29, 2015 #10
    A lot of thanks to everyone for your suggestions. I'll try and commenting.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Collect2: ld returned 1 exit status
  1. IM status checker (Replies: 3)

  2. C++: exit() question (Replies: 10)

Loading...