您可以使用此 autoconf 宏来查找某个成员是否struct flock存在:
AC_CHECK_MEMBERS([struct flock.l_type],[],[],[[#include <fcntl.h>]])
Run Code Online (Sandbox Code Playgroud)
Github 有各种 autoconf 文件,您可以通过在 *.ac 文件中搜索“struct集群”来查看更多想法。
更新:debian-bugs 列表上的一篇旧文章讨论了struct flock顺序问题。
我们可以从该错误中获得灵感并在配置中执行此操作:
AC_MSG_CHECKING("whether flock struct is linux ordered or not")
AC_TRY_RUN([
#include <fcntl.h>
struct flock lock = { 1, 2, 3, 4, 5 };
int main() { return lock.l_type==1 ? 0 : 1; }
], [
AC_DEFINE(HAVE_FLOCK_LINUX)
AC_MSG_RESULT("yes")
], AC_MSG_RESULT("no") )
Run Code Online (Sandbox Code Playgroud)
您还可以在运行时在程序中执行此检查,它不一定是配置步骤。