简体   繁体   English

如何在不同的Linux发行版上处理不同的头文件位置?

[英]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 : 例如, libncursesncursesw5-config --cflags --libsArch上产生这个:

-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.

相关问题 如何使二进制文件与不同的发行版兼容 - How to make a binary compatible with different distributions 如何处理大小不同的Linux消息队列(POSIX或SysV)中的信号? - How to handle signals in Linux Message Queues (POSIX or SysV) with different sizes? 如何在其他头文件中使用头文件的向量? - How to use the vector of a header file in a different header file? 如何在不同的 header 文件中实现成员 function? - How to implement a member function in a different header file? 将文件保存在Linux的其他位置 - Saving a file in a different place for linux 如何从不同头文件中的类继承? - How do you inherit from a class in a different header file? 如何在cmake中使用autouic将header和ui文件放在不同的文件夹中 - How to place header and ui file in different folders using autouic in cmake Hash 表:如何在不同的 header 文件中使用在 header 文件中声明的成员 - Hash table: How to use members declared in a header file in a different header file C ++ - 如何正确地将default_random_engine绑定到两个不同的uniform_int_distributions - C++ - How to correctly bind a default_random_engine to two different uniform_int_distributions 将图像文件(.bmp)复制到其他位置 - Duplicating an image file (.bmp) to a different location
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM