Search code examples
clinuxubuntueclipse-cdt

O_DIRECT undeclared, Eclipse CDT, Ubuntu 20.04


I am experiencing an issue with O_DIRECT. I am trying to use it with open(), but I get an error like:

error: O_DIRECT undeclared (first use in this function)

I am including <fcntl.h>

I grepped /usr/include/ directory for O_DIRECT and it exists in x86_64-linux-gnu/bits/fcntl-linux.h. I tried to include this file instead, but then I get this error:

error: #error Never use <x86_64-linux-gnu/bits/fcntl-linux.h> directly; include <fcntl.h> instead.

I am trying to all of this in Eclipse CDT project on newly installed Ubuntu 20.04 system.


Solution

  • You should define _GNU_SOURCE before including <fcntl.h> or add -D_GNU_SOURCE to your compiler command.

    Note that this reduces portability of your program.