Karnivaurus
Karnivaurus

Reputation: 24131

How to search for header files in usr/include/linux

I am writing a C++ program with cmake in Ubuntu, which uses the header file joystick.h in /usr/include/linux. By default, it does not seem that make can find joystick.h in the default directories if I use #include <joystick.h>. Therefore, I add the line include_directories (/usr/include/linux) to CMakeLists.txt to enable this header to be found.

The problem is, I now get all sorts of errors such as error: redefinition of ‘struct timeval’ and error: redefinition of ‘struct timezone’. This seems to be because there is a header time.h in both /user/include and /usr/include/linux. The header guards in these files are #ifndef _TIME_H and #ifndef _LINUX_TIME_H respectively. Therefore, the only solution I can think of is to hardcode the path to joystick.h in my source code.

Because of this, it seems to me that /usr/include/linux should never be added to the search path due to these redefinition issues. Is this correct? And is my solution of hardcoding the path the best one?

Upvotes: 3

Views: 950

Answers (1)

Etan Reisner
Etan Reisner

Reputation: 81012

Unless there is a reason not to (and there might be I suppose) it would seem that just using #include <linux/joystick.h> in the source file would be the simplest solution here.

Upvotes: 2

Related Questions