How to handle the location of different headers in different Linux distributions?

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

In my case, this is fitsio.h from cfitsio, which is here in OpenSUSE 12.1:

#include <cfitsio/fitsio.h> 

and here in Arch Linux:

 #include <fitsio.h> 

I think I can use some preprocessor directives to create the switch. I can use this for testing if I am on Linux or Windows, etc., but I don’t know what I can use to check if I am on Arch Linux or not.

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

+5
source share
2 answers

Keep it simple

 #include <fitsio.h> 

Then, in the additional include directories, specify the paths to the directories containing this header for both SUSE and Arch:

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

Even if the former does not exist in Arch, it will not cause any problems at compile time.

+7
source

Some libraries have a [libraryname]-config program that displays the correct compiler flags that will be used when compiling with this library on the current platform.

For example, libncurses ' ncursesw5-config --cflags --libs produces this on Arch :

 -L/usr/lib -lncursesw 

and this is on Debian :

 -I/usr/include/ncursesw -lncursesw -ltinfo 

Having #include <curses.h> in the C code, then it will be enough and will compile correctly in both distributions.

+1
source

Source: https://habr.com/ru/post/1210108/


All Articles