Discussion:
lab0 error
(too old to reply)
Jilla Bejan
2004-01-11 02:18:08 UTC
Permalink
My program compiles and works correctly when I use the gcc compiler at
home. When i transfered my files to ecf and compiled it, i got no errors
or warning, but when i tried to link assn0.o and palindrome.o into an
executable file, i get the following error message and the exe file is not
created:
assn0.o: In function `main':
assn0.o(.text+0x17): the `gets' function is dangerous and should not be
used.
assn0.o(.text+0x3b): undefined reference to `is_verbatim_palindrome_index'
assn0.o(.text+0x77): undefined reference to `is_verbatim_palindrome_ptr'
collect2: ld returned 1 exit status

Any idea what the problem might be?
Thanks
Bejan



C
Alexander Smith
2004-01-11 18:34:02 UTC
Permalink
Hi Bejan,

You have one warning and two errors. Ignore the warning about using
"gets". (See below.) The two errors come from the linker. This is the
linker saying that it cannot find the functions
is_verbatim_palindrome_index() and is_verbatim_palindrome_ptr() - which
are the two functions you are supposed to write. You might have misspelled
the functions in palindrome.c, or made a typo in the parameters or return
value. If you are sure you have gotten that right, then you must not be
linking them properly. When you say you "tried to link assn0.o and
palindrome.o into an executable", what do you mean? You should be using
the makefile provided to compile your programs. That means you should be
able to just type "make". If you wanted to link them manually, then you
would type:
gcc assn0.o palindrome.o -o palindrome

One more possibility comes to mind: are you sure you transfered the files
to your school account correctly? You should be transfering them to your
ECF account - not your ugsparc account. Open up the file in a text editor
on one of the p##.ecf machines and make sure it contains what you think it
should. Also remember that UNIX and Linux are case sensitive, but Windows
is not. So, on the ECF machines, "assn0.c" and "Assn0.c" are two different
files.


About the "gets" warning:
assn0.c uses the gets() funciton. This function reads characters from
stdin into a character buffer until it reaches a newline character or the
end-of-file marker. But there is no way to specify how large the input
buffer is; so, if the user enters a string that is too long, it will
clobber whatever is in memory after it. This is called a "buffer overrun",
and is a very common cause of security holes in commercial software that
you've probably heard so much about. gets() is part of the C standard; it
was introduced a long time ago, before these kinds of security exploits
were common. It seems that, in an attempt to encourage C programmers to
write safer code, the current maintainers of gcc have decided to cause a
warning to be generated whenever gets() is used. It is certainly a good
idea to get into the practice of writing safe code, but for the sake of
simplicity, we won't go overboard with that in this course.

In general, your code should compile without errors or warnings, but for
assn0, the warning is coming from code which we have provided you, so
there's nothing you can do about it. (You won't lose marks, of course.) I
can guarantee that this will NOT happen in future labs. For assn1 on, the
code we give you will not generate any warnings.


Alexander Smith
Post by Jilla Bejan
My program compiles and works correctly when I use the gcc compiler at
home. When i transfered my files to ecf and compiled it, i got no errors
or warning, but when i tried to link assn0.o and palindrome.o into an
executable file, i get the following error message and the exe file is not
assn0.o(.text+0x17): the `gets' function is dangerous and should not be
used.
assn0.o(.text+0x3b): undefined reference to `is_verbatim_palindrome_index'
assn0.o(.text+0x77): undefined reference to `is_verbatim_palindrome_ptr'
collect2: ld returned 1 exit status
Any idea what the problem might be?
Thanks
Bejan
C
Continue reading on narkive:
Loading...