LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-20-2007, 12:08 AM   #1
xaos5
Member
 
Registered: Dec 2004
Distribution: debian and slackware
Posts: 217

Rep: Reputation: 31
trying to compile simple inotify C program


Code:
#include <stdio.h>
#include <stdlib.h>

#include <sys/inotify.h>
//#include <linux/inotify.h>

int main(int argc, char *argv[])
{
  int fd = inotify_init();
  if ( fd < 0 )
  {
    printf("inotify init failed with error # %d\n", fd);
    exit(-1);
  }
  
  return 0;
}
Code:
# using #include <sys/inotify.h>:
$ g++ inotify.cpp
inotify.cpp:4:25: error: sys/inotify.h: No such file or directory
inotify.cpp: In function ‘int main(int, char**)’:
inotify.cpp:9: error: ‘inotify_init’ was not declared in this scope

# using #include <linux/inotify.h>:
$ g++ inotify.cpp
inotify.cpp: In function ‘int main(int, char**)’:
inotify.cpp:9: error: ‘inotify_init’ was not declared in this scope
Code:
$ find / -iname *inotify.h*
/usr/src/linux-headers-2.6.18-5/include/linux/inotify.h
/usr/src/linux-headers-2.6.18-5-amd64/include/linux/inotify.h
/usr/src/linux-headers-2.6.18-5-amd64/include/config/inotify.h
/usr/include/linux/inotify.h
/usr/include/inotifytools/inotify.h
Debian Etch amd64. What am I doing wrong here?

Last edited by xaos5; 12-20-2007 at 12:10 AM.
 
Old 12-20-2007, 01:21 AM   #2
SciYro
Senior Member
 
Registered: Oct 2003
Location: hopefully not here
Distribution: Gentoo
Posts: 2,038

Rep: Reputation: 51
Why are you using a C++ compiler for a C program? Try it with "gcc" and see what happens.

edit: why did you also name the source file as a C++ one?
 
Old 12-20-2007, 01:31 AM   #3
xaos5
Member
 
Registered: Dec 2004
Distribution: debian and slackware
Posts: 217

Original Poster
Rep: Reputation: 31
EDIT2: I think I found a solution, debian etch only has libc6 2.3.6, where inotify needs 2.5 or higher... looks like I have to start grabbing some files from lenny and report back.

#include <linux/inotify.h>:
Code:
$ gcc test.c
/tmp/ccUbw3ZY.o: In function `main':
test.c:(.text+0x15): undefined reference to `inotify_init'
collect2: ld returned 1 exit status
#include <sys/inotify.h>:
Code:
gcc test.c
test.c:4:25: error: sys/inotify.h: No such file or directory
I originally started off with #include <iostream> as I'm used to writing c++ programs.


edit: Here is someone else with the same problem with no resolve: http://www.nabble.com/inotify-proble...to8869928.html

Last edited by xaos5; 12-20-2007 at 01:55 AM.
 
Old 12-20-2007, 03:11 AM   #4
SciYro
Senior Member
 
Registered: Oct 2003
Location: hopefully not here
Distribution: Gentoo
Posts: 2,038

Rep: Reputation: 51
Seems like it probably is your libc version, glibc 2.6.1 here and your program compiles and runs fine. Looking at the binary, it seems to only have a significant link with libc, so if you get that linker error, i do believe it means your libc doesn't have the function contained.
 
Old 12-20-2007, 08:07 PM   #5
xaos5
Member
 
Registered: Dec 2004
Distribution: debian and slackware
Posts: 217

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by SciYro View Post
Seems like it probably is your libc version, glibc 2.6.1 here and your program compiles and runs fine. Looking at the binary, it seems to only have a significant link with libc, so if you get that linker error, i do believe it means your libc doesn't have the function contained.
As I suspected, your right. My example now compiles perfectly.

Code:
$ dpkg -l libc6
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name           Version        Description
+++-==============-==============-============================================
ii  libc6          2.7-4          GNU C Library: Shared libraries
less /etc/apt/sources.list:
Code:
# stable
deb http://ftp.debian.org/debian/ etch main non-free contrib
deb-src http://ftp.debian.org/debian/ etch main non-free contrib

# testing
deb http://ftp.debian.org/debian/ lenny main non-free contrib
deb-src http://ftp.debian.org/debian/ lenny main non-free contrib


deb http://security.debian.org/ etch/updates main contrib
deb-src http://security.debian.org/ etch/updates main contrib
less /etc/apt/preferences:
Code:
Package: *
Pin: release a=stable
Pin-Priority: 700

Package: *
Pin: release a=lenny
Pin-Priority: 650
Code:
# apt-get install -t testing libc6
 
Old 12-20-2007, 09:01 PM   #6
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
The test program compiles OK in Ubuntu Feisty using gcc and #include <sys/inotify.h>.

This file is taken from /usr/include/sys/inotify.h, and belongs to the libc6-dev package, so just check to see that you have the -dev package installed as well as the runtime package, libc6.
 
  


Reply

Tags
programming


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple program wont compile BACTRATE Linux - Software 14 07-24-2008 12:57 PM
Trying to compile simple program, mysql_connect error. anybody help me krisvamc Linux - Software 6 06-20-2007 06:24 PM
Mounting Inotify? trscookie Linux - Software 1 12-19-2005 01:37 PM
Is inotify worth it? aneel.d Linux - General 0 10-14-2005 10:49 PM
Why doesn't this simple program compile? SparceMatrix Programming 4 08-27-2002 03:37 AM


All times are GMT -5. The time now is 09:57 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration