• Re: problem with inotify.h

    From The Natural Philosopher@3:770/3 to zeneca on Sat Jul 9 13:23:04 2022
    On 09/07/2022 10:10, zeneca wrote:
    Le 9/07/22 à 10:18, Richard Kettlewell a écrit :
    zeneca <pasIci@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>.


    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.

    $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

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Richard Kettlewell@3:770/3 to Jim Jackson on Sun Jul 10 12:07:12 2022
    Jim Jackson <jj@franjam.org.uk> writes:
    On 2022-07-09, Richard Kettlewell <invalid@invalid.invalid> wrote:
    zeneca <pasIci@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/

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)