gpt4 book ai didi

包含 ucontext.h 时无法编译

转载 作者:太空狗 更新时间:2023-10-29 12:04:18 24 4
gpt4 key购买 nike

使用 gcc,我在编译使用 ucontext.h 的东西时遇到这些错误

    /usr/include/sys/ucontext.h: At top level:
/usr/include/sys/ucontext.h:138: error: expected identifier or ‘(’ before numeric constant
/usr/include/sys/ucontext.h:139: error: expected ‘;’ before ‘stack_t’

查看 ucontext.h,这似乎是导致的原因:

    134 /* Userlevel context.  */
135 typedef struct ucontext
136 {
137 unsigned long int uc_flags;
138 struct ucontext *uc_link;
139 stack_t uc_stack;
140 mcontext_t uc_mcontext;
141 __sigset_t uc_sigmask;
142 struct _libc_fpstate __fpregs_mem;
143 } ucontext_t;

第 138 行和 139 行如何引发这些错误?不知道该怎么做,因为这是一个标准的 sys header 。

最佳答案

这个问题可能是由于代码中某处的#define将uc_link定义为某个整数引起的。

例子:

#define uc_link 22

在 Unix/Linux 中找到它的最有效方法是在源代码目录上运行 grep -r "uc_link".。如果您使用 git 来管理您的源代码,您可以使用 git grep "uc_link" 代替。

如果此定义存在于一个文件中,并且您在其中使用了 ucontext.h,那么您应该尝试将 ucontext 逻辑与需要此 #define 的逻辑分离。

此外,我必须指出,#define 不是 ALL_CAPS 是一种不好的做法。您遇到的问题很好地体现了其中一个原因,另一个原因是每个人都希望它们是 ALL_CAPS,而您的代码对于可能希望与您合作的其他程序员而言变得更难理解和可读。

关于包含 ucontext.h 时无法编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20665478/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com