undefined reference to `link'

Discussion in 'C Programming' started by Jinsong Zhao, Nov 1, 2011.

  1. Jinsong Zhao

    Jinsong Zhao Guest

    Hi there,

    I tried to compile a c program
    (http://people.sc.fsu.edu/~jburkardt/c_src/f77split/f77split.c) using
    MinGW/gcc 4.6.1:

    gcc f77split.c

    however, I get the following error message:

    f77split.c:(.text+0x4a9): undefined reference to `link'
    collect2: ld returned 1 exit status

    However, compiled the same code with gcc 4.4.x on a Linux machine, and
    succeed.

    Does it mean I missing something on my Windows XP with MinGW/gcc 4.6.1?

    Any suggestions will be really appreciated.

    Regards,
    Jinsong
     
    Jinsong Zhao, Nov 1, 2011
    #1
    1. Advertising

  2. Jinsong Zhao

    Mark Bluemel Guest

    On 11/01/2011 03:41 PM, Jinsong Zhao wrote:
    > Hi there,
    >
    > I tried to compile a c program
    > (http://people.sc.fsu.edu/~jburkardt/c_src/f77split/f77split.c) using
    > MinGW/gcc 4.6.1:
    >
    > gcc f77split.c
    >
    > however, I get the following error message:
    >
    > f77split.c:(.text+0x4a9): undefined reference to `link'
    > collect2: ld returned 1 exit status
    >
    > However, compiled the same code with gcc 4.4.x on a Linux machine, and
    > succeed.
    >
    > Does it mean I missing something on my Windows XP with MinGW/gcc 4.6.1?
    >
    > Any suggestions will be really appreciated.


    The code tries to use the link() (and unlink() I think) routines which
    are part of POSIX, not C. They'll be present on a Linux/Unix system, but
    probably not on Windows, even wth MinGW.
     
    Mark Bluemel, Nov 1, 2011
    #2
    1. Advertising

  3. Jinsong Zhao

    Jinsong Zhao Guest

    On 2011-11-1 23:46, Mark Bluemel wrote:
    > On 11/01/2011 03:41 PM, Jinsong Zhao wrote:
    >> Hi there,
    >>
    >> I tried to compile a c program
    >> (http://people.sc.fsu.edu/~jburkardt/c_src/f77split/f77split.c) using
    >> MinGW/gcc 4.6.1:
    >>
    >> gcc f77split.c
    >>
    >> however, I get the following error message:
    >>
    >> f77split.c:(.text+0x4a9): undefined reference to `link'
    >> collect2: ld returned 1 exit status
    >>
    >> However, compiled the same code with gcc 4.4.x on a Linux machine, and
    >> succeed.
    >>
    >> Does it mean I missing something on my Windows XP with MinGW/gcc 4.6.1?
    >>
    >> Any suggestions will be really appreciated.

    >
    > The code tries to use the link() (and unlink() I think) routines which
    > are part of POSIX, not C. They'll be present on a Linux/Unix system, but
    > probably not on Windows, even wth MinGW.


    yes, the code use link and unlink routines.

    Is it possible to compile the code on Windows? If yes, how to change the
    code?

    Thanks.

    Regards,
    Jinsong
     
    Jinsong Zhao, Nov 1, 2011
    #3
  4. Jinsong Zhao

    Mark Bluemel Guest

    On 11/01/2011 04:01 PM, Jinsong Zhao wrote:
    > On 2011-11-1 23:46, Mark Bluemel wrote:
    >> On 11/01/2011 03:41 PM, Jinsong Zhao wrote:
    >>> Hi there,
    >>>
    >>> I tried to compile a c program
    >>> (http://people.sc.fsu.edu/~jburkardt/c_src/f77split/f77split.c) using
    >>> MinGW/gcc 4.6.1:
    >>>
    >>> gcc f77split.c
    >>>
    >>> however, I get the following error message:
    >>>
    >>> f77split.c:(.text+0x4a9): undefined reference to `link'
    >>> collect2: ld returned 1 exit status
    >>>
    >>> However, compiled the same code with gcc 4.4.x on a Linux machine, and
    >>> succeed.
    >>>
    >>> Does it mean I missing something on my Windows XP with MinGW/gcc 4.6.1?
    >>>
    >>> Any suggestions will be really appreciated.

    >>
    >> The code tries to use the link() (and unlink() I think) routines which
    >> are part of POSIX, not C. They'll be present on a Linux/Unix system, but
    >> probably not on Windows, even wth MinGW.

    >
    > yes, the code use link and unlink routines.
    >
    > Is it possible to compile the code on Windows? If yes, how to change the
    > code?


    You need to work out what the link and unlink routines are being used
    for - I think it's to rename a temporary work file to become an output
    file - and then write appropriate code to do that using routines which
    are available on Windows. You probably should ask in a windows forum for
    help with those routines.
     
    Mark Bluemel, Nov 1, 2011
    #4
  5. On 2011-11-01, Jinsong Zhao <> wrote:
    > On 2011-11-1 23:46, Mark Bluemel wrote:
    >> On 11/01/2011 03:41 PM, Jinsong Zhao wrote:
    >>> Hi there,
    >>>
    >>> I tried to compile a c program
    >>> (http://people.sc.fsu.edu/~jburkardt/c_src/f77split/f77split.c) using
    >>> MinGW/gcc 4.6.1:
    >>>
    >>> gcc f77split.c
    >>>
    >>> however, I get the following error message:
    >>>
    >>> f77split.c:(.text+0x4a9): undefined reference to `link'
    >>> collect2: ld returned 1 exit status
    >>>
    >>> However, compiled the same code with gcc 4.4.x on a Linux machine, and
    >>> succeed.
    >>>
    >>> Does it mean I missing something on my Windows XP with MinGW/gcc 4.6.1?
    >>>
    >>> Any suggestions will be really appreciated.

    >>
    >> The code tries to use the link() (and unlink() I think) routines which
    >> are part of POSIX, not C. They'll be present on a Linux/Unix system, but
    >> probably not on Windows, even wth MinGW.

    >
    > yes, the code use link and unlink routines.
    >
    > Is it possible to compile the code on Windows? If yes, how to change the
    > code?


    Cygwin may have `link`/`unlink`. Try it.

    --
    Best Regards,
    Mike Manilone.
     
    Mike Manilone, Nov 2, 2011
    #5
  6. Jinsong Zhao

    jgharston Guest

    Mark Bluemel wrote:
    > > yes, the code use link and unlink routines.

    > You need to work out what the link and unlink routines are being used
    > for - I think it's to rename a temporary work file to become an output


    If you're using link/unlink to rename a file, the stdio library
    contains
    the standard rename() function.

    Always start by looking in your standard libraries for the
    functionality
    you're looking for before going trekking off in other directions.

    JGH
     
    jgharston, Nov 2, 2011
    #6
  7. jgharston <> writes:
    > Mark Bluemel wrote:
    >> > yes, the code use link and unlink routines.

    >> You need to work out what the link and unlink routines are being used
    >> for - I think it's to rename a temporary work file to become an output

    >
    > If you're using link/unlink to rename a file, the stdio library
    > contains
    > the standard rename() function.
    >
    > Always start by looking in your standard libraries for the
    > functionality you're looking for before going trekking off in other
    > directions.


    rename() doesn't do what the Unix link() system call does.

    link() creates a new name for a file. The new name and the old name
    both refer to the same file in the same way; neither of them is, in any
    real sense, the original.

    The C standard library doesn't provide anything with equivalent
    functionality -- probably because there's no guarantee that the
    underlying OS or filesystem is capable of supporting it.

    (I tried using the "ln" command under Cygwin, a Unix emulation layer
    that runs on top of MS Windows, and got some odd and inconsistent
    results.)

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Nov 2, 2011
    #7
  8. (Gordon Burditt) writes:
    [...]
    > Note that the link/unlink procedure assumes that this can be done
    > repeatedly: if the destination file already exists (left over from
    > the last time the code was executed), it is removed; then the rename
    > is done.


    Not according to the link(2) man page on my system:

    If newpath exists it will not be overwritten.

    And link() is *not* a form of renaming. It creates a new name for a
    file; the old name continues to exist.

    [...]

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Nov 2, 2011
    #8
  9. (Gordon Burditt) writes:
    > Read the code containing two unlink() calls and one link() call.
    > *THAT CODE*, not link() alone, performs a rough equivalent of a
    > rename().

    [...]

    What is this in response to? (check parent article) Oh, I see, this is
    a followup to my post, and since I've told you not to quote my words
    without attribution, you've decided to post followups without quoting
    me at all.

    In the future, I request that you don't do this.

    I explicitly deny permission to quote my words without attribution. I
    ask that you not post followups to my articles without quoting my words.

    The obvious solution is to quote with attribution, as everyone else
    does. If you're paranoid, you can use an attribution line that doesn't
    claim that I *really* wrote the quoted words, like "Someone claiming to
    be Keith Thompson writes:".

    Another solution would be just not to post followups to anything I
    write. And if that's inconvenient, I suggest that it's entirely your
    own fault.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Nov 3, 2011
    #9
  10. Jinsong Zhao

    Kaz Kylheku Guest

    On 2011-11-01, Jinsong Zhao <> wrote:
    > f77split.c:(.text+0x4a9): undefined reference to `link'
    > collect2: ld returned 1 exit status


    The external name "link", or even "please_link", does not guarantee results. :)
     
    Kaz Kylheku, Nov 3, 2011
    #10
  11. Jinsong Zhao

    Seebs Guest

    On 2011-11-03, Gordon Burditt <> wrote:
    >> [unattributed quote]


    This is really annoying. It is completely pointless. It does not
    provide you with any legal protection that I've ever heard of, and it
    makes it much harder to follow your "contributions" to conversations.

    .... enough harder that I, for one, am just plonking you because it's
    not worth the hassle of trying to figure out who you don't think you
    were really responding to.

    -s
    --
    Copyright 2011, all wrongs reversed. Peter Seebach /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
    I am not speaking for my employer, although they do rent some of my opinions.
     
    Seebs, Nov 3, 2011
    #11
  12. Jinsong Zhao

    Kaz Kylheku Guest

    On 2011-11-03, Seebs <> wrote:
    > On 2011-11-03, Gordon Burditt <> wrote:
    >>> [unattributed quote]

    >
    > This is really annoying. It is completely pointless. It does not


    I don't see the big problem. Gordon left the parent article reference intact,
    so it's easy to see where the quote came from.

    In slrn: ESC-P fetches the parent article. There it is: "Acid Washed".
     
    Kaz Kylheku, Nov 3, 2011
    #12
  13. Kaz Kylheku <> writes:
    > On 2011-11-03, Seebs <> wrote:
    >> On 2011-11-03, Gordon Burditt <> wrote:
    >>>> [unattributed quote]

    >>
    >> This is really annoying. It is completely pointless. It does not

    >
    > I don't see the big problem. Gordon left the parent article reference intact,
    > so it's easy to see where the quote came from.
    >
    > In slrn: ESC-P fetches the parent article. There it is: "Acid Washed".


    Then why did you bother to quote the parent article?

    In the newsreader I use (Gnus), it's easy to jump to the parent
    article, but it can be difficult to get back (or maybe there's a
    command I don't know about). The vast majority of posters here quote
    enough of the parent article that I rarely need to bother. I find
    Gordon's stubborn refusal to attribute quoted text inexplicable
    and annoying. (Though I do give him credit for respecting my wishes
    by not quoting my text without attribution.)

    And there's a solution that would simultaneously make Gordon's
    articles as easy to read as anyone else's and satisfy his paranoia.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Nov 3, 2011
    #13
  14. Jinsong Zhao

    Seebs Guest

    On 2011-11-03, Kaz Kylheku <> wrote:
    > I don't see the big problem. Gordon left the parent article reference intact,
    > so it's easy to see where the quote came from.


    If the other article happens to be available.

    > In slrn: ESC-P fetches the parent article. There it is: "Acid Washed".


    Some people read news offline. I'm one of them. And while in theory I can
    go around navigating article trees to look stuff up, in practice, it breaks
    the general rule that I don't like to spend more effort than the reward I
    get.

    I don't desperately need to read his posts. I'm not going to if making sense
    of them requires more effort than making sense of normal Usenet posts does.

    -s
    --
    Copyright 2011, all wrongs reversed. Peter Seebach /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
    I am not speaking for my employer, although they do rent some of my opinions.
     
    Seebs, Nov 3, 2011
    #14
  15. Jinsong Zhao

    Geoff Guest

    On Wed, 02 Nov 2011 00:01:58 +0800, Jinsong Zhao <>
    wrote:

    >Is it possible to compile the code on Windows? If yes, how to change the
    >code?


    Yes.

    Delete this line (line 5):
    # include <unistd.h>
    It's for POSIX and it's not needed for Windows and you won't need the
    link and unlink POSIXisms below.

    Instead of (line 563):

    if ( unlink(file_out_name),link(file_temp_name, file_out_name) == -1
    ||
    unlink(file_temp_name) == -1)
    {

    write:

    if ( rename(file_temp_name, file_out_name) == -1 )
    {

    Instead of (line 606):

    if ( unlink ( file_temp_name ) == -1)
    {

    write:

    if ( remove ( file_temp_name ) == -1)
    {
     
    Geoff, Nov 3, 2011
    #15
  16. Jinsong Zhao

    jgharston Guest

    Keith Thompson wrote:
    > jgharston wrote:
    > > If you're using link/unlink to rename a file, the stdio library
    > > contains the standard rename() function.

    >
    > rename() doesn't do what the Unix link() system call does.


    That's why I wrote "If you're using link/unlink to rename a file..."

    JGH
     
    jgharston, Nov 4, 2011
    #16
  17. jgharston <> writes:
    > Keith Thompson wrote:
    >> jgharston wrote:
    >> > If you're using link/unlink to rename a file, the stdio library
    >> > contains the standard rename() function.

    >>
    >> rename() doesn't do what the Unix link() system call does.

    >
    > That's why I wrote "If you're using link/unlink to rename a file..."


    Ok, I didn't pay enough attention to the context.

    But why would you use link and unlink to rename a file in the first
    place? rename() exists both as a Unix system call and as a standard C
    library function.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Nov 4, 2011
    #17
  18. Jinsong Zhao

    Jinsong Zhao Guest

    On 2011-11-4 5:52, Geoff wrote:
    > On Wed, 02 Nov 2011 00:01:58 +0800, Jinsong Zhao<>
    > wrote:
    >
    >> Is it possible to compile the code on Windows? If yes, how to change the
    >> code?

    >
    > Yes.
    >
    > Delete this line (line 5):
    > # include<unistd.h>
    > It's for POSIX and it's not needed for Windows and you won't need the
    > link and unlink POSIXisms below.
    >
    > Instead of (line 563):
    >
    > if ( unlink(file_out_name),link(file_temp_name, file_out_name) == -1
    > ||
    > unlink(file_temp_name) == -1)
    > {
    >
    > write:
    >
    > if ( rename(file_temp_name, file_out_name) == -1 )
    > {
    >
    > Instead of (line 606):
    >
    > if ( unlink ( file_temp_name ) == -1)
    > {
    >
    > write:
    >
    > if ( remove ( file_temp_name ) == -1)
    > {
    >


    Thank you very much. it now could be compiled without any error.

    However, it does not work as expected. It gave the following error message:

    E:\f77split>a f77split_prb.f
    Splitting f77split_prb.f.

    F77SPLIT: Error!
    Cannot move "fsplit.XXXXX" to "alpha.f".

    Regards,
    Jinsong
     
    Jinsong Zhao, Nov 4, 2011
    #18
  19. Jinsong Zhao

    Geoff Guest

    On Fri, 04 Nov 2011 08:19:27 +0800, Jinsong Zhao <>
    wrote:

    >On 2011-11-4 5:52, Geoff wrote:
    >> On Wed, 02 Nov 2011 00:01:58 +0800, Jinsong Zhao<>
    >> wrote:
    >>
    >>> Is it possible to compile the code on Windows? If yes, how to change the
    >>> code?

    >>
    >> Yes.
    >>
    >> Delete this line (line 5):
    >> # include<unistd.h>
    >> It's for POSIX and it's not needed for Windows and you won't need the
    >> link and unlink POSIXisms below.
    >>
    >> Instead of (line 563):
    >>
    >> if ( unlink(file_out_name),link(file_temp_name, file_out_name) == -1
    >> ||
    >> unlink(file_temp_name) == -1)
    >> {
    >>
    >> write:
    >>
    >> if ( rename(file_temp_name, file_out_name) == -1 )
    >> {
    >>
    >> Instead of (line 606):
    >>
    >> if ( unlink ( file_temp_name ) == -1)
    >> {
    >>
    >> write:
    >>
    >> if ( remove ( file_temp_name ) == -1)
    >> {
    >>

    >
    >Thank you very much. it now could be compiled without any error.
    >
    >However, it does not work as expected. It gave the following error message:
    >
    >E:\f77split>a f77split_prb.f
    >Splitting f77split_prb.f.
    >
    >F77SPLIT: Error!
    > Cannot move "fsplit.XXXXX" to "alpha.f".
    >
    >Regards,
    >Jinsong


    Amend line 563 to read:
    if ( remove(file_out_name), rename(file_temp_name, file_out_name)
    == -1 )
     
    Geoff, Nov 4, 2011
    #19
  20. Jinsong Zhao

    Jinsong Zhao Guest

    On 2011-11-4 12:32, Geoff wrote:
    > remove(file_out_name), rename(file_temp_name, file_out_name
     
    Jinsong Zhao, Nov 4, 2011
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Spencer

    Re: Link Link Link DANGER WILL ROBINSON!!!

    Kevin Spencer, May 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    904
    Kevin Spencer
    May 17, 2005
  2. Mantorok Redgormor
    Replies:
    70
    Views:
    1,825
    Dan Pop
    Feb 17, 2004
  3. Axter
    Replies:
    0
    Views:
    467
    Axter
    Jan 17, 2006
  4. Replies:
    1
    Views:
    503
    Mark Rae [MVP]
    Sep 20, 2007
  5. VK
    Replies:
    45
    Views:
    655
    Dr John Stockton
    Sep 12, 2006
Loading...

Share This Page