undefined reference to `inotify_init1'











up vote
1
down vote

favorite
1












I am trying to integrate latest version 2.80 of dnsmasq application in my project. The platform is Linux 2.6.32.
Compilation with cross compiler arm-none-linux-gnueabi-gcc is giving this error:



inotify.o: In function `inotify_dnsmasq_init':
inotify.c:(.text+0x514): undefined reference to `inotify_init1'


It seems that function inotify_init1() is not supported in this platform.



I'm wondering if I can write this function by myself.



int inotify_init1(int flags)
{
int flags1 = 0;
int inotify_fd = inotify_init();

if ((inotify_fd != -1) && (flags != 0))
{
if((flags1 = fcntl(inotify_fd, F_GETFL)) != -1)
{
fcntl(inotify_fd, F_SETFL, flags1 | flags);
}
}
return inotify_fd;
}


Would the piece of code do the job?



Update:
according to inotify_init man page, inotify_init1() was added to glibc in version 2.9. I am working with glibc version 2.8 only



In an other hand I see that inotify_init1 is present in several files in Kernel:



1) /fs/notify/inotify/inotify_user.c
/* inotify syscalls */
SYSCALL_DEFINE1(inotify_init1, int, flags)
{
...
}
2) /kernel/sys_ni.c
cond_syscall(sys_inotify_init1);


I understand that I am missing something but I don't know if the appropriate library is built or properly linked on the dnsmasq building files.



Thank you for advising.










share|improve this question




















  • 1




    Do you link to the corresponding library?
    – Yastanub
    Nov 8 at 14:14










  • Isn't it is the same library as inotify_init() ?
    – Gaston
    Nov 8 at 14:16










  • i do not know this library but it sounds like you are missing to link the libwhateveritiscalled.a to your executable
    – Yastanub
    Nov 8 at 14:18












  • As i can read out of inotify_init man page you seem to need to link against glibc. I am not sure since i do not work as much with linux and its man pages.
    – Yastanub
    Nov 8 at 14:21






  • 1




    Have you built the library already? There must be some lib file missing or you forget to link it. I can not say for sure since you do not show any code but this is most likely the problem when it comes to undefined reference errors.
    – Yastanub
    Nov 8 at 14:54















up vote
1
down vote

favorite
1












I am trying to integrate latest version 2.80 of dnsmasq application in my project. The platform is Linux 2.6.32.
Compilation with cross compiler arm-none-linux-gnueabi-gcc is giving this error:



inotify.o: In function `inotify_dnsmasq_init':
inotify.c:(.text+0x514): undefined reference to `inotify_init1'


It seems that function inotify_init1() is not supported in this platform.



I'm wondering if I can write this function by myself.



int inotify_init1(int flags)
{
int flags1 = 0;
int inotify_fd = inotify_init();

if ((inotify_fd != -1) && (flags != 0))
{
if((flags1 = fcntl(inotify_fd, F_GETFL)) != -1)
{
fcntl(inotify_fd, F_SETFL, flags1 | flags);
}
}
return inotify_fd;
}


Would the piece of code do the job?



Update:
according to inotify_init man page, inotify_init1() was added to glibc in version 2.9. I am working with glibc version 2.8 only



In an other hand I see that inotify_init1 is present in several files in Kernel:



1) /fs/notify/inotify/inotify_user.c
/* inotify syscalls */
SYSCALL_DEFINE1(inotify_init1, int, flags)
{
...
}
2) /kernel/sys_ni.c
cond_syscall(sys_inotify_init1);


I understand that I am missing something but I don't know if the appropriate library is built or properly linked on the dnsmasq building files.



Thank you for advising.










share|improve this question




















  • 1




    Do you link to the corresponding library?
    – Yastanub
    Nov 8 at 14:14










  • Isn't it is the same library as inotify_init() ?
    – Gaston
    Nov 8 at 14:16










  • i do not know this library but it sounds like you are missing to link the libwhateveritiscalled.a to your executable
    – Yastanub
    Nov 8 at 14:18












  • As i can read out of inotify_init man page you seem to need to link against glibc. I am not sure since i do not work as much with linux and its man pages.
    – Yastanub
    Nov 8 at 14:21






  • 1




    Have you built the library already? There must be some lib file missing or you forget to link it. I can not say for sure since you do not show any code but this is most likely the problem when it comes to undefined reference errors.
    – Yastanub
    Nov 8 at 14:54













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





I am trying to integrate latest version 2.80 of dnsmasq application in my project. The platform is Linux 2.6.32.
Compilation with cross compiler arm-none-linux-gnueabi-gcc is giving this error:



inotify.o: In function `inotify_dnsmasq_init':
inotify.c:(.text+0x514): undefined reference to `inotify_init1'


It seems that function inotify_init1() is not supported in this platform.



I'm wondering if I can write this function by myself.



int inotify_init1(int flags)
{
int flags1 = 0;
int inotify_fd = inotify_init();

if ((inotify_fd != -1) && (flags != 0))
{
if((flags1 = fcntl(inotify_fd, F_GETFL)) != -1)
{
fcntl(inotify_fd, F_SETFL, flags1 | flags);
}
}
return inotify_fd;
}


Would the piece of code do the job?



Update:
according to inotify_init man page, inotify_init1() was added to glibc in version 2.9. I am working with glibc version 2.8 only



In an other hand I see that inotify_init1 is present in several files in Kernel:



1) /fs/notify/inotify/inotify_user.c
/* inotify syscalls */
SYSCALL_DEFINE1(inotify_init1, int, flags)
{
...
}
2) /kernel/sys_ni.c
cond_syscall(sys_inotify_init1);


I understand that I am missing something but I don't know if the appropriate library is built or properly linked on the dnsmasq building files.



Thank you for advising.










share|improve this question















I am trying to integrate latest version 2.80 of dnsmasq application in my project. The platform is Linux 2.6.32.
Compilation with cross compiler arm-none-linux-gnueabi-gcc is giving this error:



inotify.o: In function `inotify_dnsmasq_init':
inotify.c:(.text+0x514): undefined reference to `inotify_init1'


It seems that function inotify_init1() is not supported in this platform.



I'm wondering if I can write this function by myself.



int inotify_init1(int flags)
{
int flags1 = 0;
int inotify_fd = inotify_init();

if ((inotify_fd != -1) && (flags != 0))
{
if((flags1 = fcntl(inotify_fd, F_GETFL)) != -1)
{
fcntl(inotify_fd, F_SETFL, flags1 | flags);
}
}
return inotify_fd;
}


Would the piece of code do the job?



Update:
according to inotify_init man page, inotify_init1() was added to glibc in version 2.9. I am working with glibc version 2.8 only



In an other hand I see that inotify_init1 is present in several files in Kernel:



1) /fs/notify/inotify/inotify_user.c
/* inotify syscalls */
SYSCALL_DEFINE1(inotify_init1, int, flags)
{
...
}
2) /kernel/sys_ni.c
cond_syscall(sys_inotify_init1);


I understand that I am missing something but I don't know if the appropriate library is built or properly linked on the dnsmasq building files.



Thank you for advising.







c linux-kernel embedded-linux dnsmasq






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 15:51

























asked Nov 8 at 14:08









Gaston

3401625




3401625








  • 1




    Do you link to the corresponding library?
    – Yastanub
    Nov 8 at 14:14










  • Isn't it is the same library as inotify_init() ?
    – Gaston
    Nov 8 at 14:16










  • i do not know this library but it sounds like you are missing to link the libwhateveritiscalled.a to your executable
    – Yastanub
    Nov 8 at 14:18












  • As i can read out of inotify_init man page you seem to need to link against glibc. I am not sure since i do not work as much with linux and its man pages.
    – Yastanub
    Nov 8 at 14:21






  • 1




    Have you built the library already? There must be some lib file missing or you forget to link it. I can not say for sure since you do not show any code but this is most likely the problem when it comes to undefined reference errors.
    – Yastanub
    Nov 8 at 14:54














  • 1




    Do you link to the corresponding library?
    – Yastanub
    Nov 8 at 14:14










  • Isn't it is the same library as inotify_init() ?
    – Gaston
    Nov 8 at 14:16










  • i do not know this library but it sounds like you are missing to link the libwhateveritiscalled.a to your executable
    – Yastanub
    Nov 8 at 14:18












  • As i can read out of inotify_init man page you seem to need to link against glibc. I am not sure since i do not work as much with linux and its man pages.
    – Yastanub
    Nov 8 at 14:21






  • 1




    Have you built the library already? There must be some lib file missing or you forget to link it. I can not say for sure since you do not show any code but this is most likely the problem when it comes to undefined reference errors.
    – Yastanub
    Nov 8 at 14:54








1




1




Do you link to the corresponding library?
– Yastanub
Nov 8 at 14:14




Do you link to the corresponding library?
– Yastanub
Nov 8 at 14:14












Isn't it is the same library as inotify_init() ?
– Gaston
Nov 8 at 14:16




Isn't it is the same library as inotify_init() ?
– Gaston
Nov 8 at 14:16












i do not know this library but it sounds like you are missing to link the libwhateveritiscalled.a to your executable
– Yastanub
Nov 8 at 14:18






i do not know this library but it sounds like you are missing to link the libwhateveritiscalled.a to your executable
– Yastanub
Nov 8 at 14:18














As i can read out of inotify_init man page you seem to need to link against glibc. I am not sure since i do not work as much with linux and its man pages.
– Yastanub
Nov 8 at 14:21




As i can read out of inotify_init man page you seem to need to link against glibc. I am not sure since i do not work as much with linux and its man pages.
– Yastanub
Nov 8 at 14:21




1




1




Have you built the library already? There must be some lib file missing or you forget to link it. I can not say for sure since you do not show any code but this is most likely the problem when it comes to undefined reference errors.
– Yastanub
Nov 8 at 14:54




Have you built the library already? There must be some lib file missing or you forget to link it. I can not say for sure since you do not show any code but this is most likely the problem when it comes to undefined reference errors.
– Yastanub
Nov 8 at 14:54












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted
+50










You function looks ok and should work. I don't know however how your application defines the macros IN_NONBLOCK and IN_CLOEXEC. Looking at kernel srcrs they should be defined the same as O_NONBLOCK and O_CLOEXEC. Also would be nice to add if (flags & ~(IN_CLOEXEC | IN_NONBLOCK)) return -EINVAL; some checking.



I would add a file inotify.h to your project / to dnsmasq sources, which I would add to include path:



#ifndef MY_INOTIFY_H_
#define MY_INOTIFY_H_
#include_next <inotify.h>

// from https://github.molgen.mpg.de/git-mirror/glibc/blob/glibc-2.9/sysdeps/unix/sysv/linux/sys/inotify.h#L25
/* Flags for the parameter of inotify_init1. */
enum
{
IN_CLOEXEC = 02000000,
#define IN_CLOEXEC IN_CLOEXEC
IN_NONBLOCK = 04000
#define IN_NONBLOCK IN_NONBLOCK
};

extern int inotify_init1 (int flags) __THROW;
// or just int inotify_init1(int flags); ...

#endif


Along with it your wrapper in a c file added to compilation / linking. The include_next serves as a simple overwrite of the glibc inotify.h.



If you kernel supports inotify_wait1 syscall and I think it does. You can even check if__NR_inotify_wait1 is defined in your unistd.h. You can just:



   #define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>

int inotify_init1(int flags) {
return syscall(332, flags);
}


To make a syscall just call a syscall() function.






share|improve this answer



















  • 1




    OK, thank you, let me a chance to check all this later.
    – Gaston
    Nov 13 at 9:05






  • 1




    It helps a lot to understand this topic. Thank you.
    – Gaston
    Nov 13 at 16:16











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53209432%2fundefined-reference-to-inotify-init1%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted
+50










You function looks ok and should work. I don't know however how your application defines the macros IN_NONBLOCK and IN_CLOEXEC. Looking at kernel srcrs they should be defined the same as O_NONBLOCK and O_CLOEXEC. Also would be nice to add if (flags & ~(IN_CLOEXEC | IN_NONBLOCK)) return -EINVAL; some checking.



I would add a file inotify.h to your project / to dnsmasq sources, which I would add to include path:



#ifndef MY_INOTIFY_H_
#define MY_INOTIFY_H_
#include_next <inotify.h>

// from https://github.molgen.mpg.de/git-mirror/glibc/blob/glibc-2.9/sysdeps/unix/sysv/linux/sys/inotify.h#L25
/* Flags for the parameter of inotify_init1. */
enum
{
IN_CLOEXEC = 02000000,
#define IN_CLOEXEC IN_CLOEXEC
IN_NONBLOCK = 04000
#define IN_NONBLOCK IN_NONBLOCK
};

extern int inotify_init1 (int flags) __THROW;
// or just int inotify_init1(int flags); ...

#endif


Along with it your wrapper in a c file added to compilation / linking. The include_next serves as a simple overwrite of the glibc inotify.h.



If you kernel supports inotify_wait1 syscall and I think it does. You can even check if__NR_inotify_wait1 is defined in your unistd.h. You can just:



   #define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>

int inotify_init1(int flags) {
return syscall(332, flags);
}


To make a syscall just call a syscall() function.






share|improve this answer



















  • 1




    OK, thank you, let me a chance to check all this later.
    – Gaston
    Nov 13 at 9:05






  • 1




    It helps a lot to understand this topic. Thank you.
    – Gaston
    Nov 13 at 16:16















up vote
1
down vote



accepted
+50










You function looks ok and should work. I don't know however how your application defines the macros IN_NONBLOCK and IN_CLOEXEC. Looking at kernel srcrs they should be defined the same as O_NONBLOCK and O_CLOEXEC. Also would be nice to add if (flags & ~(IN_CLOEXEC | IN_NONBLOCK)) return -EINVAL; some checking.



I would add a file inotify.h to your project / to dnsmasq sources, which I would add to include path:



#ifndef MY_INOTIFY_H_
#define MY_INOTIFY_H_
#include_next <inotify.h>

// from https://github.molgen.mpg.de/git-mirror/glibc/blob/glibc-2.9/sysdeps/unix/sysv/linux/sys/inotify.h#L25
/* Flags for the parameter of inotify_init1. */
enum
{
IN_CLOEXEC = 02000000,
#define IN_CLOEXEC IN_CLOEXEC
IN_NONBLOCK = 04000
#define IN_NONBLOCK IN_NONBLOCK
};

extern int inotify_init1 (int flags) __THROW;
// or just int inotify_init1(int flags); ...

#endif


Along with it your wrapper in a c file added to compilation / linking. The include_next serves as a simple overwrite of the glibc inotify.h.



If you kernel supports inotify_wait1 syscall and I think it does. You can even check if__NR_inotify_wait1 is defined in your unistd.h. You can just:



   #define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>

int inotify_init1(int flags) {
return syscall(332, flags);
}


To make a syscall just call a syscall() function.






share|improve this answer



















  • 1




    OK, thank you, let me a chance to check all this later.
    – Gaston
    Nov 13 at 9:05






  • 1




    It helps a lot to understand this topic. Thank you.
    – Gaston
    Nov 13 at 16:16













up vote
1
down vote



accepted
+50







up vote
1
down vote



accepted
+50




+50




You function looks ok and should work. I don't know however how your application defines the macros IN_NONBLOCK and IN_CLOEXEC. Looking at kernel srcrs they should be defined the same as O_NONBLOCK and O_CLOEXEC. Also would be nice to add if (flags & ~(IN_CLOEXEC | IN_NONBLOCK)) return -EINVAL; some checking.



I would add a file inotify.h to your project / to dnsmasq sources, which I would add to include path:



#ifndef MY_INOTIFY_H_
#define MY_INOTIFY_H_
#include_next <inotify.h>

// from https://github.molgen.mpg.de/git-mirror/glibc/blob/glibc-2.9/sysdeps/unix/sysv/linux/sys/inotify.h#L25
/* Flags for the parameter of inotify_init1. */
enum
{
IN_CLOEXEC = 02000000,
#define IN_CLOEXEC IN_CLOEXEC
IN_NONBLOCK = 04000
#define IN_NONBLOCK IN_NONBLOCK
};

extern int inotify_init1 (int flags) __THROW;
// or just int inotify_init1(int flags); ...

#endif


Along with it your wrapper in a c file added to compilation / linking. The include_next serves as a simple overwrite of the glibc inotify.h.



If you kernel supports inotify_wait1 syscall and I think it does. You can even check if__NR_inotify_wait1 is defined in your unistd.h. You can just:



   #define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>

int inotify_init1(int flags) {
return syscall(332, flags);
}


To make a syscall just call a syscall() function.






share|improve this answer














You function looks ok and should work. I don't know however how your application defines the macros IN_NONBLOCK and IN_CLOEXEC. Looking at kernel srcrs they should be defined the same as O_NONBLOCK and O_CLOEXEC. Also would be nice to add if (flags & ~(IN_CLOEXEC | IN_NONBLOCK)) return -EINVAL; some checking.



I would add a file inotify.h to your project / to dnsmasq sources, which I would add to include path:



#ifndef MY_INOTIFY_H_
#define MY_INOTIFY_H_
#include_next <inotify.h>

// from https://github.molgen.mpg.de/git-mirror/glibc/blob/glibc-2.9/sysdeps/unix/sysv/linux/sys/inotify.h#L25
/* Flags for the parameter of inotify_init1. */
enum
{
IN_CLOEXEC = 02000000,
#define IN_CLOEXEC IN_CLOEXEC
IN_NONBLOCK = 04000
#define IN_NONBLOCK IN_NONBLOCK
};

extern int inotify_init1 (int flags) __THROW;
// or just int inotify_init1(int flags); ...

#endif


Along with it your wrapper in a c file added to compilation / linking. The include_next serves as a simple overwrite of the glibc inotify.h.



If you kernel supports inotify_wait1 syscall and I think it does. You can even check if__NR_inotify_wait1 is defined in your unistd.h. You can just:



   #define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>

int inotify_init1(int flags) {
return syscall(332, flags);
}


To make a syscall just call a syscall() function.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 13 at 9:33

























answered Nov 13 at 8:55









Kamil Cuk

8,0601222




8,0601222








  • 1




    OK, thank you, let me a chance to check all this later.
    – Gaston
    Nov 13 at 9:05






  • 1




    It helps a lot to understand this topic. Thank you.
    – Gaston
    Nov 13 at 16:16














  • 1




    OK, thank you, let me a chance to check all this later.
    – Gaston
    Nov 13 at 9:05






  • 1




    It helps a lot to understand this topic. Thank you.
    – Gaston
    Nov 13 at 16:16








1




1




OK, thank you, let me a chance to check all this later.
– Gaston
Nov 13 at 9:05




OK, thank you, let me a chance to check all this later.
– Gaston
Nov 13 at 9:05




1




1




It helps a lot to understand this topic. Thank you.
– Gaston
Nov 13 at 16:16




It helps a lot to understand this topic. Thank you.
– Gaston
Nov 13 at 16:16


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53209432%2fundefined-reference-to-inotify-init1%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()