Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle different header file location on different Linux distributions?

In my code I use a header file which unfortunately has a different location under different Linux distributions.

In my case it is fitsio.h from cfitsio which is located here in OpenSUSE 12.1:

#include <cfitsio/fitsio.h>

and here in Arch Linux:

#include <fitsio.h>

I guess I can use some preprocessor directives to create a switch. I can use this to test if I am on Linux or Windows, etc. but I have no clue what I can use to test whether I am on Arch Linux or not.

Or is there another way/strategy to handle this case?

like image 962
Sjoerd222888 Avatar asked Dec 30 '14 14:12

Sjoerd222888


People also ask

How can you avoid the inclusion of multiple header files in a single source file?

To avoid multiple inclusions of the same header file we use the #ifndef, #define and #endif preprocessor directives. Just write the entire program in only file and include headers once only. You can use the conditional preprocessor directive named #ifndef to check whether that symbolic name has already been assigned.

Where are header files stored in Linux?

The C library's header files include the kernel header files from the “linux” subdirectory. The system's libc headers are usually installed at the default location /usr/include and the kernel headers in subdirectories under that (most notably /usr/include/linux and /usr/include/asm).

Where should header files be stored?

The angle brackets (<>) cause the preprocessor to search for the header file in the standard place for header files on your system, usually the /usr/include directory.

Which option in gcc is used to specify the location of the .h files?

gcc -I adds include directory of header files.


1 Answers

Keep the simpler include

#include <fitsio.h>

Then, under additional include directories, list paths to directories containing this header both for SUSE and for Arch:

/path/to/header/cfitsio
/path/to/header

Even if the former is nonexistent on Arch, it won't lead to any problems during compilation.

like image 161
Anton Poznyakovskiy Avatar answered Sep 25 '22 21:09

Anton Poznyakovskiy