2012-12-23 46 views
1

我想在Eclipse中編譯我的代碼在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:error:'O_RDWR'未在此範圍內聲明 ../src/main.cpp:330:錯誤:'open'未在此範圍內聲明

它在Eclipse之外進行編譯

任何包含或標誌我需要在Eclipse上編譯?

由於

+0

Eclipse可能使用* * *不同的編譯器來編譯你的代碼。 –

+0

這是什麼意思關於管道? –

回答

0

的EEXIST MACRO在ASM-通用/錯誤號-base.h定義和O_RDWR標誌在fcntl.h定義。

地址:

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

要包含OpenPipeRead定義文件,它應該編譯。