c – O_WRONLY undeclared (first use in this function)

c – O_WRONLY undeclared (first use in this function)

@Kevin is right. On my Arch installation, according to man fcntl.h, you need to #include <fcntl.h> to get access to O_WRONLY.

To use open(), you also need to #include <sys/stat.h>.

I have tried this code in my machine (Ubuntu 12.0.4). But I didnt get any error messages like you got.

According to the man page of open() you are probably missing #include <sys/stat.h>.

c – O_WRONLY undeclared (first use in this function)

Manual pages for open(2):

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

int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);

Please verify that you have each and every one of the required includes.

Leave a Reply

Your email address will not be published.