Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Declaration of Function compile error 1

Status
Not open for further replies.

menace212

Programmer
Jul 11, 2003
144
US
I'm attempting to write a program in c to modify,write and create to files on a Sun 8.X. I having problems compiling when I attempt to use the write and lseek commands. Should I use a function and then do a function call to manipulate the commands because currently I have them it in main..ex below:


#include </usr/include/fcntl.h>
#include </usr/include/stdio.h>
.
.
.


main()

{

int fd;

fd = open(&quot;/file&quot;, O_RDWR);

While ( read(fd) == len)
{
lseek(fd, 10, SEEK_SET);
write(fd, &quot;hello&quot;, 5);
break;
}
close(fd);
}

But the compile error give me this:

implicit declaration of function 'int lseek(...)'
implicit decalaration of function 'int write(...)
implicit declaration of function 'int close(...)




 
Implicit declaration means that, from the use of the function, the compiler can deduce (in theory) what the declaration of that function would be. However, since this declaration is apparently not provided by the programmer (and therefore it is quite likely that the definition will also be missing), the compiler stops and produces an error.

The probable cause of the error is that the functions lseek, write and close are not (yet) declared. Some solutions to the problem could be:
- Make sure you include the right header files
- If you or any library uses namespaces, be sure to mention them
- Check if you didn't make typing errors (typo in the declaration or invalid upper/lower case in the declaration or the call)

Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
Don't worry what people think about you. They're too busy wondering what you think about them.
 
Binary (via file handle) file i/o (with open, read, lseek etc) is not part of C/C++ standards. Standard header <stdio.h> includes C file stream functions prototypes (fopen, fread etc). Common place for bin i/o declarations on Solaris is <unistd.h> header.
See read() prototype before use: there are 3 parameters (handle, buffer ptr, buffer size). Or try standard stream functions from stdio (fopen, fread etc) with binary mode reading.
 
I've have stdio.h included in the declaration. Is there a substitute for lseek and write I can use like you did with fopen and fclose.
 
for lseek you need to include the following files,

#include <sys/types.h>
#include <unistd.h>

and for close

#include <unistd.h>

and so on...

Well as a thumb rule, you can find the required include files from man pages for an API.

 
Thanks everyone, I got it to work...I had the lib write, but I needed to declare the functions and use different structs..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top