无法使用 gcc 构建 sigqueue 示例,但 g++可以吗?
我有一个奇怪的构建问题。
我有一个简单的测试程序,它将 sigqueue 发送到另一个进程。
这个小代码示例在我将其构建为 C++ 程序(使用 g++ 编译)时构建并运行 但是当我将它编译为 ac 程序(使用 gcc)时,我收到一个错误,他找不到 sigval 结构。
简短的示例:
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
int main(int argc, char *argv[])
{
sigval value;
value.sival_int = 123;
sigqueue(0,SIGUSR1, value);
}
请注意,我将 pid 替换为 0 以简化这个问题。
如果我用 gcc 编译,我会得到:
$> gcc sigusr1_mini.c
sigusr1_mini.c: In function ‘main’:
sigusr1_mini.c:9: error: ‘sigval’ undeclared (first use in this function)
sigusr1_mini.c:9: error: (Each undeclared identifier is reported only once
sigusr1_mini.c:9: error: for each function it appears in.)
sigusr1_mini.c:9: error: expected ‘;’ before ‘value’
sigusr1_mini.c:10: error: ‘value’ undeclared (first use in this function)
我在这里缺少什么,为什么他找不到 sigval 结构? 为什么g++能找到呢?
谢谢 约翰
I have a strange build problem.
I have a simple test program that sends a sigqueue to another process.
This little code example builds and runs when I build it as a c++ program (compiled with g++)
but when I compile it as a c program (with gcc) I get a error that he can't find the sigval struct.
The short example:
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
int main(int argc, char *argv[])
{
sigval value;
value.sival_int = 123;
sigqueue(0,SIGUSR1, value);
}
Please note that I replaced the pid with 0 to simplify this question.
And if I compile with gcc I get this:
gt; gcc sigusr1_mini.c
sigusr1_mini.c: In function ‘main’:
sigusr1_mini.c:9: error: ‘sigval’ undeclared (first use in this function)
sigusr1_mini.c:9: error: (Each undeclared identifier is reported only once
sigusr1_mini.c:9: error: for each function it appears in.)
sigusr1_mini.c:9: error: expected ‘;’ before ‘value’
sigusr1_mini.c:10: error: ‘value’ undeclared (first use in this function)
What am I missing here, why can't he find the sigval struct?
And why can g++ find it?
Thanks
Johan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 C 中,
struct
和union
标记不会像在 C++ 中那样引入可以单独使用的名称。您必须将其拼写出来:In C,
struct
andunion
tags do not introduce names that can be used on their own like they do in C++. You must spell it out:h 文件中的 sigval 是如何定义的? C编译器可能需要完整的定义,例如:
union sigval值;
How is sigval defined in h-file? C compiler may require full definition, for example:
union sigval value;