Mohammad Amir
Mohammad Amir

Reputation: 353

Error: implicit declaration of function `int open(...)'

I am using open function in one of my C++ project on Solaris OS.

#include <sys/types.h> 
#include <sys/stat.h> 
#include <fcntl.h>

char in_pathname[PATH_MAX];
int  in_fd = -1;
in_fd = ::open(in_pathname, (O_RDWR|O_CREAT|O_TRUNC), 0600);

Using the above line I am getting following compilation error.

implicit declaration of function `int open(...)'

Any idea why its happening.

Note: This source code is very old and I am using gcc version 2.95.3 to compile it.

Upvotes: 1

Views: 7782

Answers (1)

doctorlove
doctorlove

Reputation: 19282

Some (older) compilers will let you use a function you haven't declared and assume it returns int.

This will happen if you use a file but haven't included the header it is declared in. You seem to be using file's open method, and these docs suggest you therefore need

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

Upvotes: 1

Related Questions