ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello all, I would like to develop a pplication with inotify.
Now my code is stupid, but it does yet error.
When I try 'gcc myprogram.c -o myprogram' the output is:
/tmp/ccef8sAa.o(.text+0x1d): In function 'main':
:undefined reference to 'inotify_init'
collect2: ld retuned 1 exit status
It seems that it don't find inotify_init. I tried 'grep INOTIFY /boot/config' and output is:
CONFIG_INOTIFY=y
CONFIG_INOTIFY_USER=y
The command 'man inotify_init' return man page of above syscall.
What is the problem?
Is there someone that it can help me?
I have a Slackware 11, then I suppose that I am using glibc-2.3.6.
Inotify.h did not present in /usr/include/sys, but I copied inotify.h from /usr/src/linux/fs
Quote:
Was it compiled with inotify support?
No, but I installed a precompiled kernel 2.6.18 provided with distribution (test26.s)
No, but I installed a precompiled kernel 2.6.18 provided with distribution (test26.s)
If such is the case (i.e., your glibc has no built-in inotify support), you need to use the system calls directly. Your originally posted problem is a linking one and thus can be fixed if you identify your own inotify functions wrapping the linux system calls. E.g. (from inotify-syscalls.h):
What are steps that I need to do exactly?
What I must add to code?
Thanks
You have a few options:
If you have a the file <sys/inotify-syscalls.h> in your include path, just include that file at the beginning of each source file you need it in.
Make your own inotify-syscalls.h header with the lines of the previous post (of course you need to surround the code with #ifndef _LINUX_INOTIFY_SYSCALLS_H\
#define _LINUX_INOTIFY_SYSCALLS_H at the beginning and #endif at the end as is custom with C header files). Include it at the beginning of each source file you need it in.
Put the lines from the previous post at the beginning of each source file you need it in.
The important thing is to have the definitions of the wrapper functions (which will most likely be inlined anyway) visible to the rest of source, so they are not assumed by the compiler to reside in an external library (e.g., glibc), and so that the linker does not complain when they are not found in the aforementioned library.
Also, you might want to take a look at this (though it’s a bit old).
Exactly, what is __u32 in inotify?
The event->mask field in declared as __u32.
How can I to compare __u32 with an integer? for example '__u32 == IN_ACCESS'
Exactly, what is __u32 in inotify?
The event->mask field in declared as __u32.
How can I to compare __u32 with an integer? for example '__u32 == IN_ACCESS'
Thanks in advance to help.
In case you did’t figure it out yet, __u32 is an unsigned 32-bit integer storage unit. It can be compared with a literal numeral value easily.
Quote:
Originally Posted by shifter
Now my problem is the following:
if (event->mask & IN_ISDIR) printf("IS A DIRECTORY");
but gcc outputs 'error: dereferencing pointer to incomplete type'.
Now what is the problem????
I am despaired...
In your code, is “event” a pointer to a struct inotify_event or is event itself a struct inotify_event? You can’t use pointer syntax with a struct (i.e., instead of “event->mask” try “event.mask”).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.