简体   繁体   English

无法使用gcc构建sigqueue示例,但g ++可以吗?

[英]Can't build sigqueue example with gcc but g++ is ok?

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 ac program (with gcc) I get a error that he can't find the sigval struct. 当我将其构建为c ++程序(与g ++编译)时,会生成并运行此小代码示例,但是当我将其作为ac程序(与gcc一起编译)时,会出现一个错误,即他找不到sigval结构。

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. 请注意,我将pid替换为0以简化此问题。

And if I compile with gcc I get this: 如果我使用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)

What am I missing here, why can't he find the sigval struct? 我在这里想念的是什么,他为什么找不到sigval结构? And why can g++ find it? 为什么g ++可以找到它?

Thanks Johan 谢谢约翰

In C, struct and union tags do not introduce names that can be used on their own like they do in C++. 在C语言中, structunion标记不会引入可以像在C ++中那样单独使用的名称。 You must spell it out: 您必须说明:

union sigval value;

How is sigval defined in h-file? H文件中的sigval如何定义? C compiler may require full definition, for example: C编译器可能需要完整的定义,例如:

union sigval value; 联合信号值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM