在Eclipse中使用管道

时间:2012-12-23 14:45:06

标签: c++ eclipse pipe

我正在尝试在Eclipse中编译我的代码

但它不会编译我的管道使用。

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <syslog.h>
#include <signal.h>
#include <map>
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <sys/wait.h>



using namespace std;
int OpenPipeRead(string sinterface)
{
int ret_val,errno;
string lpipename="",lpipepath="";
lpipepath = mconfig[C_PIPEPATH];
lpipename.append(lpipepath);                    //Its not empty only when there is argument for parallal telepath_sniff instances.
lpipename.append(mconfig[C_PIPENAME]);
if(strcmp(sinterface.c_str(), "") != 0)
    lpipename.append("_" + sinterface);             
printf("Trying to open Pipe for reading\n");
syslog(LOG_INFO, "Try to open Pipe for reading\n"); 
/* Create the named - pipe */
ret_val = mkfifo(lpipename.c_str(), 0666);
if ((ret_val == -1) && (errno != EEXIST)) {
    perror("Error creating the named pipe");
    syslog(LOG_ERR, "Error creating the named pipe");           
    exit(1);
}       
if((pipehandler = open(lpipename.c_str(), O_RDWR)) < 1)     /* Open the pipe for reading and writing , in append mode */
{
    perror("Failed to open pipe file");
    syslog(LOG_ERR, "Failed to open pipe file");
    exit(1);
}
printf("Pipe opened.\n");
syslog(LOG_INFO, "Pipe opened.\n");

}

int main(){
    OpenPipeRead("arg");

}

错误是:

../ src / main.cpp:325:错误:未在此范围内声明'EEXIST' ../src/main.cpp:330:错误:未在此范围内声明'O_RDWR' ../src/main.cpp:330:错误:未在此范围内声明'open'

它在Eclipse之外编译

我需要在Eclipse上编译的任何包含或标志吗?

由于

1 个答案:

答案 0 :(得分:0)

EEXIST MACRO在asm-generic / errno-base.h中定义,O_RDWR Flag在fcntl.h中定义。

添加:

#include <asm-generic/errno-base.h>
#include <fcntl.h>

到包含OpenPipeRead定义的文件,它应该编译。