problem with inotify.h

Jul 08, 2022 Last reply: 4 years ago 11 Replies

I am trying to compile a small prog with inotify but compilation fail:



Inotify.c:19:8: warning: implicit declaration of function ‘inotify_init’ [-Wimplicit-function-declaration] fd = inotify_init(); ^~~~~~~~~~~~ Inotify.c:27:8: warning: implicit declaration of function ‘inotify_add_watch’ [-Wimplicit-function-declaration] wd = inotify_add_watch( fd, "/sys/bus/w1/devices/28-000003f1a254/temperature", IN_MODIFY | IN_DELETE ); .. ..



Any idea?? Many thanks


how are you calling the compiler. You should be using -I (for the includes) and -L (for the library path)

something like

gcc -I/usr/include -L/usr/lib -l somelib source.c -o output.bin

Looks like your source should have the following among the other includes:

#include <sys/inotify.h>

Have you run "man inotify" and read its descriptionof the inotify APIs?

#include <linux/inotify.h>

There are some differences betwen inotify.h pn raspberry and inotify.h on Centos 7.9, some ref to extern inotify_init and other are missing on raspberry. The man page doen't give more interresting info for compiling.

My Makefile contains: OPTION=-I/usr/include/mysql -L/usr/lib64/mysql -L/usr/mysql/lib

-lmysqlclient -lpthread -lz -lm -lrt -lssl -lcrypto -ldl -lrt -std=gnu99

xosta: Osta.c config.h nokia_routine.c 5110_routines.h charGenerator.h if [ -f gpit ]; then $(RM) xosta;fi $(CC) $(OPTION) -lwiringPi Osta.c nokia_routine.c -o xosta

Thanks

This is a bad guess for two reasons:

  • GCC already searches in the right places, there is no need to specify extra -I or -L options for system headers and libraries.
  • The error isn’t about a #include file or library not being found. Adding -I or -L options will not make any difference.

That will not work. As the man page says, it should be <sys/inotify.h>.

Indeed. It is usually about an include file not being specified *at all*. So calls to external functions are undefined as to type, so assumed to be 'int'

-- “It is not the truth of Marxism that explains the willingness of intellectuals to believe it, but the power that it confers on intellectuals, in their attempts to control the world. And since...it is futile to reason someone out of a thing that he was not reasoned into, we can conclude that Marxism owes its remarkable power to survive every criticism to the fact that it is not a truth-directed but a power-directed system of thought.” Sir Roger Scruton

As I said, there is no /usr/include/sys/ directory on Raspberry On Centos7.9 there are /usr/include/sys/inotify.h AND /usr/include/linux/inotify.h

on Centos7.9 the very same program run with #include <linux/inotify.h>

but compile fail on raspberry.

You’ve been given the answer. If you don’t like it, that’s your problem.

$find /usr/include -name inotify.h

/usr/include/linux/inotify.h /usr/include/arm-linux-gnueabihf/bits/inotify.h /usr/include/arm-linux-gnueabihf/sys/inotify.h

On my pi these are 3 different file lengths $ ls -l /usr/include/linux/inotify.h

-rw-r--r-- 1 root root 2914 Mar 31 2018 /usr/include/linux/inotify.h $ ls -l /usr/include/arm-linux-gnueabihf/bits/inotify.h

-rw-r--r-- 1 root root 1079 Feb 6 2019 /usr/include/arm-linux-gnueabihf/bits/inotify.h $ ls -l /usr/include/arm-linux-gnueabihf/sys/inotify.h

-rw-r--r-- 1 root root 3837 Feb 6 2019 /usr/include/arm-linux-gnueabihf/sys/inotify.h

This suggests that (a) there is an implicit preload of the include path /usr/include/arm-linux-gnueabihf/

and (b) that if <sys/inotify.h> works that is in fact the correct file

Or (c) that richard and the man page are wrong.

Not very helpfull.

I think maybe the inotify webpage is wrong on debian based systems.

On an Intel Debian abased system I have ...

# cd /usr/include/ # find . -name inotify.h ./linux/inotify.h ./x86_64-linux-gnu/sys/inotify.h ./x86_64-linux-gnu/bits/inotify.h

and on a raspberry pi ...

# cd /usr/include/ # find . -name inotify.h ./arm-linux-gnueabihf/sys/inotify.h ./linux/inotify.h

# find . -name inotify.h -exec grep inotify_init {} /dev/null \; ./arm-linux-gnueabihf/sys/inotify.h:/* Flags for the parameter of inotify_init1. */ ./arm-linux-gnueabihf/sys/inotify.h:extern int inotify_init (void) __THROW; ./arm-linux-gnueabihf/sys/inotify.h:extern int inotify_init1 (int __flags) __THROW;

I believe that the arch. specific sys includes are default. So you should only need ...

#include <inotify.h>

HTH Jim

If people don’t like being giventhe right answer then they cannot be helped.

It is not wrong.

That will also not work. I guess you didn’t bother to try it.

I made a minimal example program with inotify() and compiled it on my Pi3 (running Raspbian 10) without any complaints. Please do not run the executable, it dies not do anything sensible.

--- clip clip ---

#include <sys/inotify.h>

#include <stdlib.h>

int main(void) { int fd, fd1, wd;

fd = inotify_init(); fd1 = inotify_init1(IN_NONBLOCK); wd = inotify_add_watch(fd, "nosuchfile", IN_OPEN | IN_CLOSE);

return EXIT_SUCCESS; }

--- clip clip ---

If you are compiling on another computer than the target Raspberry, please make sure that the compiler does not use the header files or dynamic library files of the host computer.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required