Linux: Conflicts using inotify with fcntl - c++

I'm having a strange linking issue after I included inotify in my program to monitor changes to a filesystem. The project includes <fcntl.h> in many other source files. However, when I include <sys/inotify.h> in the source file which is doing the directory monitoring, I get this error:
/usr/include/fcntl.h:30:1: error: expected initializer before ‘extern’
__BEGIN_DECLS
My project uses CMake, although that doesn't seem to be relevant for finding inotify. It IS finding the inotify declarations to my knowledge, since when I included , it threw an error that inotify_init() and the other functions I used were not defined. Inotify includes fcntl and is partially built on top of some of the functionality there, so my first thought was that it's importing a different version of fcntl than the rest of my program.
In ObjectManager.h:
#ifndef MANAGE_OBJECT_H
#define MANAGE_OBJECT_H
#include "config.h"
//includes all lua headers under extern 'C'
#include <lua.hpp>
#include <list>
#include <unordered_map>
#include <pthread.h>
class ObjectManager //...
The only thing that changed was ObjectManager.cc, with the addition of sys/notify and the implementation of the watcher (not included because this is a linking issue):
#include "config.h"
#include "ObjectManager.h"
#include "Control.h"
#ifdef OBJECT_MANAGER_ENABLED
#include <string.h>
#include <stdio.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <vector>
#include <unistd.h>
#include <fstream>
#include <sys/inotify.h>
//... inotify implementation
Where Control.h declares #include <fcntl.h>.
This is the closest issue I found, related to some problems in the implementation of different fcntl headers for userspace usage. https://lkml.org/lkml/2008/9/16/98
The same problem occurs on Linux 2.6 running on Centos 6 and Linux 4.0 running on Centos 7.
Any ideas on what is causing this error and how to successfully include inotify?

Resolution: A function definition lacked a semicolon at the END of ObjectManager.h right before a #endif, and the resulting GCC error that propagated through the next includes in a complicated manner, resulting in a strange preprocessor error in fcntl.h.

Related

Why file sys/types.h doesn't contain function definition of major(dev_t dev)?

An error is being reported when I use the function major(st_dev) in my code:
"‘major’ was not declared in this scope"
Looking up documentation in the man page, it suggests that the file sys/types.h contains the definition major(dev_t dev). When I check the file /usr/include/sys/types.h on Linux version 5.10.76-linuxkit, it doesn't contains definition of major(dev_t dev).
I believe the missing definition of major(dev_t dev) in the file /usr/include/sys/types.h is the source of the error.
So my question is why doesn't /usr/include/sys/types.h contains the major(dev_t dev) definition as documented in the manual page 3 entry?
major(3) - Linux man page
Name
makedev, major, minor - manage a device number
Synopsis
#define BSD SOURCE /* See feature test macros(7) */
#include <sys/types.h>
dev_t makedev(int maj, int min);
unsigned int major(dev_t dev);
unsigned int minor(dev_t dev);
Description
The code is below:
#include <vector>
#include <map>
#include <iostream>
#include <fstream>
#include <string>
#include <stdint.h>
#include <cstring>
#include <unistd.h>
#include <sys/stat.h>
major(statbuf.st_dev);
The BSD include file <sys/types.h> originally created in 1982.
On Linux, the helper include <sys/types.h> also includes the <features.h> file. The provided function of this file has changed over time on Linux. That documentation is old, as it refers to BSD_SOURCE. In current versions, BSD_SOURCE is an alias for _DEFAULT_SOURCE.
To obtain those macros, you must include the <sys/sysmacros.h> file.

identifier "ParseNetworkString" is undefined although I included the header files

MSVC keeps telling me that ParseNetworkString is undefined.
But I've done:
#include <Winsock2.h>
#include <Ws2tcpip.h>
#include <iphlpapi.h>
as expressed in the remark part of the docs
Thank you.
I've had a look inside "iphlapi.h" and it states (line 1287)
// app must include winsock2.h, ws2ipdef.h, and windns.h to use this API
So when I use
#include <WinSock2.h>
#include <ws2ipdef.h>
#include <WinDNS.h>
#include <iphlpapi.h>
ParseNetworkString becomes available.
So it seems you were on the right track, just missing the include of <WinDNS.h>

"No such file" Include issue with Boost dynamic_bitset

I'm trying to use Boost's Dynamic_bitset class for a project, and I (believe I) have taken whichever subset of files I needed from the complete library. Now I'm doing an
#include "boost/dynamic_bitset.hpp" inside my manager.cpp file, and when compiling I get this:
In file included from manager.cpp:4:0:
boost/dynamic_bitset.hpp:15:51: fatal error: boost/dynamic_bitset/dynamic_bitset.hpp: No such file or directory
The file ierarchy inside the project folder goes like this:
proj/extras.h
proj/Makefile~
proj/manager.cpp
proj/boost
proj/boost/limits.hpp
proj/boost/dynamic_bitset.hpp
proj/boost/mpl
proj/boost/mpl/if.hpp
proj/boost/mpl/has_xxx.hpp
proj/boost/iterator.hpp
proj/boost/static_assert.hpp
proj/boost/dynamic_bitset
proj/boost/dynamic_bitset/dynamic_bitset.hpp
proj/boost/dynamic_bitset/config.hpp
proj/boost/config
proj/boost/config/select_platform_config.hpp
proj/boost/config/select_compiler_config.hpp
proj/boost/config/user.hpp
proj/boost/config/suffix.hpp
proj/boost/config/select_stdlib_config.hpp
proj/boost/dynamic_bitset_fwd.hpp
proj/boost/config.hpp
proj/boost/type_traits
proj/boost/type_traits/is_same.hpp
proj/boost/type_traits/is_pointer.hpp
proj/boost/type_traits/remove_pointer.hpp
proj/boost/type_traits/remove_const.hpp
proj/boost/type_traits/is_base_and_derived.hpp
proj/boost/type_traits/detail
proj/boost/type_traits/detail/bool_trait_def.hpp
proj/boost/type_traits/detail/yes_no_type.hpp
proj/boost/pending
proj/boost/pending/integer_log2.hpp
proj/boost/detail
proj/boost/detail/limits.hpp
proj/boost/detail/dynamic_bitset.hpp
proj/boost/detail/workaround.hpp
proj/boost/lowest_bit.hpp
proj/Makefile
proj/generator.cpp~
proj/generator.cpp
This same project compiles fine on my university's linux systems(g++ 4.2.4 there but I doubt it matters), but fails to do so (with the above error) on my Ubuntu laptop. Why isn't it finding the file since it evidently exists?
All my includes are as such:
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include "boost/dynamic_bitset.hpp"
#include <cmath>
#include <list>
#include <unistd.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <errno.h>
#include <wait.h>
#include <time.h>
#include "extras.h"
compilation is done simply with
g++ -o manager manager.c
or
g++ -Iboost -o manager manager.c
if I want to explicitely include the (local..) folder
-I .
At least if you are compiling in the same directory that contains boost.
You wrote -Iboost and #include "boost/…". So it looks in ./boost if there is a boost subdirectory.

why does xcode 4.4.1 give error while trying to use getaddrinfo ?

I am using xcode 4.4.1 to do socket programming in c++. I think i have included required header file. But i still get error saying:
" No matching function for call to 'getaddrinfo' ".
There was duplicate question here
The header files that i have included are
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>

SHGetSpecialFolderPath() Not Declared in This Scope

I am not able to compile my program SHGetSpecialFolderPath() not being declared in the scope of the program, while the correct header is being included (according to MSDN)
http://msdn.microsoft.com/en-us/library/bb762204(v=vs.85).aspx
Here are the headers for my project:
#include <iostream>
#include <iostream>
#include <windows.h>
#include <algorithm>
#include <vector>
#include <fstream>
#include <direct.h>
#include <shlobj.h>
With error:
C:\Users\user\Documents\getAppData\main.cpp|31|error: `SHGetSpecialFolderPath' was not declared in this scope
with shlobj.h being the header with the declaration in it.
Any ideas why the compiler is throwing the error? Here is how I am calling the function:
char appData[MAX_PATH];
SHGetSpecialFolderPath( NULL
,appData
,CSIDL_LOCAL_APPDATA
,1 );
cout << appData << endl;
Thanks!
From the MSDN page:
The Microsoft Internet Explorer 4.0
Desktop Update must be installed for
this function to be available.
With Windows 2000, this function is
superseded by ShGetFolderPath. You can
use this function on earlier systems
by including the redistributable DLL,
ShFolder.dll.
Perhaps this is your problem?