Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

problem with inotify.h

172 views
Skip to first unread message

zeneca

unread,
Jul 8, 2022, 10:10:26 AM7/8/22
to
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

Deloptes

unread,
Jul 8, 2022, 12:05:41 PM7/8/22
to
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


Martin Gregorie

unread,
Jul 8, 2022, 12:37:42 PM7/8/22
to
On Fri, 08 Jul 2022 18:05:40 +0200, Deloptes wrote:

> zeneca wrote:
>
>> I am trying to compile a small prog with inotify but compilation fail:
>>
>> Inotify.c:19:8: warning: implicit declaration of function
>> ‘q’
>> [-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?








--

Martin | martin at
Gregorie | gregorie dot org

zeneca

unread,
Jul 9, 2022, 3:25:12 AM7/9/22
to
Le 8/07/22 à 18:37, Martin Gregorie a écrit :
#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

Richard Kettlewell

unread,
Jul 9, 2022, 4:17:19 AM7/9/22
to
zeneca <pas...@ailleur.fr> writes:
> Le 8/07/22 à 18:37, Martin Gregorie a écrit :
>> On Fri, 08 Jul 2022 18:05:40 +0200, Deloptes wrote:
>>> zeneca wrote:
>>>
>>>> I am trying to compile a small prog with inotify but compilation fail:
>>>>
>>>> Inotify.c:19:8: warning: implicit declaration of function
>>>> ‘q’
>>>> [-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

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.

>> 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>

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

--
https://www.greenend.org.uk/rjk/

The Natural Philosopher

unread,
Jul 9, 2022, 4:57:06 AM7/9/22
to
On 09/07/2022 09:18, Richard Kettlewell wrote:
> * The error isn’t about a #include file or library not being found.
> Adding -I or -L options will not make any difference.

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

zeneca

unread,
Jul 9, 2022, 5:10:58 AM7/9/22
to
Le 9/07/22 à 10:18, Richard Kettlewell a écrit :
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.

Richard Kettlewell

unread,
Jul 9, 2022, 7:58:58 AM7/9/22
to
zeneca <pas...@ailleur.fr> writes:
> Le 9/07/22 à 10:18, Richard Kettlewell a écrit :
>> That will not work. As the man page says, it should be <sys/inotify.h>.
>
> 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.

--
https://www.greenend.org.uk/rjk/

The Natural Philosopher

unread,
Jul 9, 2022, 8:23:06 AM7/9/22
to
$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.


--
“Ideas are inherently conservative. They yield not to the attack of
other ideas but to the massive onslaught of circumstance"

- John K Galbraith

Jim Jackson

unread,
Jul 9, 2022, 10:32:05 AM7/9/22
to
On 2022-07-09, Richard Kettlewell <inv...@invalid.invalid> wrote:
> zeneca <pas...@ailleur.fr> writes:
>> Le 9/07/22 ?? 10:18, Richard Kettlewell a ??crit??:
>>> That will not work. As the man page says, it should be <sys/inotify.h>.
>>
>> 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.
>

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

Richard Kettlewell

unread,
Jul 10, 2022, 7:06:00 AM7/10/22
to
Jim Jackson <j...@franjam.org.uk> writes:
> On 2022-07-09, Richard Kettlewell <inv...@invalid.invalid> wrote:
>> zeneca <pas...@ailleur.fr> writes:
>>> Le 9/07/22 ?? 10:18, Richard Kettlewell a ??crit??:
>>>> That will not work. As the man page says, it should be <sys/inotify.h>.
>>>
>>> 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.
>
> Not very helpfull.

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

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

It is not wrong.

> 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>

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

--
https://www.greenend.org.uk/rjk/

Tauno Voipio

unread,
Jul 10, 2022, 12:36:04 PM7/10/22
to
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.

--

-TV
0 new messages