【发布时间】:2015-04-22 19:30:43
【问题描述】:
我正在尝试进行简单的 I/O 重定向(ls to sort)(ls|sort>f1),然后我的下一步是将 sort 的输出定向到 C 中的文件,但是在编译 gcc 时给出以下错误..请帮助我:)
代码
#include<stdio.h>
#include<fcntl.h>
#include<string.h>
#include<stdlib.h>
#include<sys/types.h>
#include<unistd.h>
int main()
{
int a,b,c,d,pfd[2],kk,i,j;
FILE *fp;
i=fork();
if(i==0)
{
pipe(pfd);
j=fork();
if(j==0)
{
close(1);
dup(pfd[1]);
close(pfd[0]);
close(pfd[1]);
excel("/bin/ls","/ls",0);
}
else
{
close(0);
dup(pfd[0]);
close(pfd[0]);
close(pfd[1]);
/*close(1);
kk=open(f.txt,O_WRONLY);
dup(kk);
*/
excel("/usr/bin/sort","/sort",0);
}
}
else
wait();
/*char k[100],pp[100],ll[]="/bin/";
printf("Enter the cmd to execut");
scanf("%s",k);
strcpy(pp,k);
strcat(ll,k);
printf("%s",ll);
system(ll);*/
return 0;
}
错误:
/tmp/cc6wIvoJ.o:
In function **main**: j.c:(.text+0x81): undefined reference to **excel** j.c:(.text+0xcf): undefined reference to **excel** collect2: error: ld returned 1 exit status
【问题讨论】:
-
错误:/tmp/cc6wIvoJ.o: In function main': j.c:(.text+0x81): undefined reference toexcel' j.c:(.text+0xcf): undefined reference to 'excel' collect2:错误:ld 返回 1 个退出状态
标签: c linux system-calls