undefined reference to `link'

J

Jinsong Zhao

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
 
M

Mark Bluemel

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.
 
J

Jinsong Zhao

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
 
M

Mark Bluemel

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.
 
M

Mike Manilone

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.
 
J

jgharston

Mark said:
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
 
K

Keith Thompson

jgharston said:
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.)
 
K

Keith Thompson

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.

[...]
 
K

Keith Thompson

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.
 
K

Kaz Kylheku

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. :)
 
S

Seebs

[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
 
K

Keith Thompson

Kaz Kylheku said:
[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.
 
S

Seebs

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
 
G

Geoff

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)
{
 
K

Keith Thompson

jgharston said:
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.
 
J

Jinsong Zhao

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
 
G

Geoff

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 )
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top