[英]Configuring C99 for eclipse for posix
I am practicing signals and I have moved from gcc to eclipse on ubuntu and I am running into some problem. 我正在练习信号,并且我已经从gcc转到ubuntu上的日食,并且遇到了一些问题。 Below code for gcc compiles fine for eclipse I get error "error: incompatible types when assigning to type 'union ' from type 'void (*)(int)'" 下面的gcc代码对于eclipse可以很好地编译,但出现错误“错误:从类型'void(*)(int)'分配给类型'union'时类型不兼容”
Looking online I see chances of error because of compiler using pre C99 version. 在网上查看,我看到由于使用C99之前版本的编译器而出错的可能性。 So I tried to make eclipse compile for C99 version and I found below link How do you configure GCC in Eclipse to use C99? 因此,我尝试将eclipse编译为C99版本,并在下面找到链接如何在Eclipse中配置GCC以使用C99?
I tried to make the change as suggested in SO link but currently my others flag has line which says " -c -fmessage-length =0 " 我试图按照SO链接中的建议进行更改,但目前我的其他标志的行显示“ -c -fmessage-length = 0”
if I add -std=c99 as suggested by post before or after that line compiler is not able to find the file itself 如果我在该行编译器之前或之后按照帖子的建议添加-std = c99,则找不到文件本身
I have assumed I am getting error because of compiler using pre C99 version. 我认为由于使用C99之前的版本的编译器而导致出现错误。 Please correct me if I am chasing in wrong direction and if its correct what would is the correct way to add -std=c99 to flag option to make eclipse use C99 如果我追错了方向,并且正确,将-std = c99添加到flag选项以使eclipse使用C99的正确方法,请更正我
Edit : Based on the answer when I changed sig_handler parameter I was able to compile without adding -std=c99 flag however adding that as suggested I run into compilation error. 编辑:基于我更改sig_handler参数时的答案,我能够在不添加-std = c99标志的情况下进行编译,但是根据建议添加该代码,我会遇到编译错误。 Below is compile line 下面是编译行
gcc -O0 -g3 -Wall -c -fmessage-length=0 -std=c99 -MMD -MP -MF " gcc -O0 -g3 -Wall -c -fmessage-length = 0 -std = c99 -MMD -MP -MF “
`odd_process.d" -MT"odd_process.d" -o "odd_process.o" "../odd_process.c`"
../odd_process.c: In function ‘main’:
../odd_process.c:13:2: error: unknown type name ‘sigset_t’
../odd_process.c:14:19: error: storage size of ‘sa’ isn’t know
n ñ
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
void sighandler(int sig)
{
printf("signal has been caught \n ");
}
int main(void)
{
sigset_t block_signal, empty_signal;
struct sigaction sa;
pid_t childid;
int i;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
**/*for below line while running on eclipse I see error which says*/
/***error: incompatible types when assigning to type ‘union <anonymous>’ from type ‘void (*)(int)’** */**
**sa.__sigaction_handler = sighandler;**
stdbuf(stdout, NULL);
if (sigaction(SIGCHLD, &sa, NULL) == -1)
{
printf("value not passed to signal handler \n ");
}
sigemptyset(&block_signal);
sigaddset(&block_signal, SIGCHLD);
if (sigprocmask(SIG_SETMASK, &block_signal, NULL) == -1)
{
printf("error occurred while setting signal mask \n");
}
childid = fork();
printf("value of child id is -- %d ", childid);
switch(childid)
{
case -1:
printf("Error condition child creation did not happen properly \n");
exit(-1);
case 0:
printf(" Child got created and will print odd number !!! ");
sleep(5);
exit(1);
default:
printf(" parent gets created !!! \n ");
break;
}
sigemptyset(&empty_signal);
sigsuspend(&empty_signal);
printf(" parent will print \n ");
for(i = 0; i < 10; i++)
{
printf("%d ", i);
}
printf("\n");
return EXIT_SUCCESS;
}
to modify the CFLAGS, (with the desired project open). 修改CFLAGS(打开所需的项目)。
project
单击菜单项project
properties
单击下拉菜单项的properties
C/C++Build
tab in the left window - to expand 点击左侧窗口中的C/C++Build
标签-展开 Settings
tab in the expanded C/C++Build
单击展开的C/C++Build
的Settings
选项卡 GCC C Comiler
tab in the second column - to expand 点击第二栏中的GCC C Comiler
标签-展开 miscellaneous
tab in the second column to select the third column 单击第二列中的miscellaneous
选项卡以选择第三列 -std=gnu99
输入其他标志,例如-std=gnu99
ok
点击ok
this may need to be done for each project 每个项目可能需要这样做
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.