I have a code in which I #include<linux/videodev2.h>
. There are three files:
one header file- includes:
stdint.h
andstdlib.h
. Defines a couple of functions, a struct, say abc, and some #define macros. One of the functions isint func(int, uint32_t, size_t, abc*);
one cpp file with a lot of methods, including definition of the functions in the .h file.
one main.cpp which has main() which has a function call to the method in the .h file (complete file below). This file is only for testing purposes.
#include "head.h" int main() { func(5, (uint32_t)5, (size_t)5, 0); return 0; }
What is see is a curious case:
- If I include
linux/videodev2.h
only in .h file,uint32_t
and other things defined in this header are not accessible by the .cpp files. (erros I get are:uint32_t was not declared in this scope
, anduint32_t does not name a type
, among others). This happens even if the first line of the .h file is#include<linux/videodev2.h>
- If I include the videodev2 header in both the cpp files, it works only if I import it (videodev2) before the .h file.
- If I use
func(5, (uint32_t)5, (size_t)5, (abc*)0);
in the main.cpp file, I get the error that abc is not declared in this scope.
I am compiling using the command: g++ main.cpp head.cpp
I am unable to figure out why is this. I would like to include the videodev2 header in the .h file since, it is almost certain that the code using the .h file will be dependent on it. But it seems that including it in .h file has no effect at all.
I must be honest here. This was C code which I had to convert to C++. I know that I am not conforming to the best practices and standards. But why is this behaviour seen?