c++ - 在 Eclipse 中使用管道

标签 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 上编译时使用的任何包含或标志吗?

谢谢

最佳答案

EEXIST 宏在 asm-generic/errno-base.h 中定义,O_RDWR 标志在 fcntl.h 中定义。

添加:

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

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

关于c++ - 在 Eclipse 中使用管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14011873/

相关文章:

c++ - 是否可以为 Visual Studio Code 安装多个 CMake 扩展?

c++ - 十六进制到字符串转换 C++/C/Qt?

android - android项目中/res中的文件夹

javascript - 无法加载 ext-all.js 文件

c - 使用两个管道进行双向消息传递中的 SIGPIPE

c++ - 我如何将数据通过管道传输到 bzip2 并从其在 Linux 上的 C++ 中的标准输出中获取结果数据?

c++ - 共同的初始序列和比对

使用 protected 构造函数和复制构造函数创建 C++ 非堆工厂对象

java - Gradle sourceDir没有为Eclipse添加defaultRootSource

python - 使用 python 多处理管道