1

コードを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 でコンパイルする必要があるインクルードまたはフラグはありますか?

ありがとう

4

1 に答える 1

0

EEXIST MACRO は asm-generic/errno-base.h で定義され、O_RDWR フラグは fcntl.h で定義されます。

追加 :

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

OpenPipeRead 定義を含むファイルに、コンパイルする必要があります。

于 2012-12-23T15:23:24.073 に答える