[英]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. 在我的代码中,我使用了一个头文件,不幸的是,它在不同的Linux发行版下具有不同的位置。
In my case it is fitsio.h from cfitsio which is located here in OpenSUSE 12.1: 在我的例子中,它是来自cfitsio的fitsio.h,它位于OpenSUSE 12.1中:
#include <cfitsio/fitsio.h>
and here in Arch Linux: 在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. 我可以用它来测试我是在Linux还是Windows等,但我不知道我可以用来测试我是否在Arch Linux上。
Or is there another way/strategy to handle this case? 还是有另一种方法/策略来处理这种情况?
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: 然后,在其他包含目录下,列出包含此标头的目录的路径,包括SUSE和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. 即使前者在Arch上不存在,也不会在编译期间导致任何问题。
Some libraries come with a [libraryname]-config
program that outputs the correct compiler flags to be using when compiling against that library on the current platform. 有些库附带了[libraryname]-config
程序,该程序在当前平台上针对该库进行编译时输出正确的编译器标志。
For example, libncurses
' ncursesw5-config --cflags --libs
produces this on Arch : 例如, libncurses
的ncursesw5-config --cflags --libs
在Arch上产生这个:
-L/usr/lib -lncursesw
and this on Debian : 这个在Debian上 :
-I/usr/include/ncursesw
-lncursesw -ltinfo
Having #include <curses.h>
in the C code is then sufficient, and will compile correctly in both distributions. 在C代码中使用#include <curses.h>
就足够了,并且可以在两个发行版中正确编译。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.