使用cygwin中的fork编译程序问题 [英] Problem compiling program using fork in cygwin
问题描述
我试图在cygwin中运行一个简单的程序,包括fork和wait。
我认为这将很容易编译,但我有问题。
I am trying to run a simple program in cygwin that includes fork and wait. I thought it would be very easy to compile but I am having problems.
#include <stdio.h>
#include <unistd.h>
void testFork(){}
int main(int argc,char* argv[]){
if (fork()==0) {testFork();return 0;}
while (wait() == -1);
return 0;
}
编译时使用:
gcc -Wall -Wextra -o test。 o test
Compiled using: gcc -Wall -Wextra -o test.o test
我得到以下错误:
C:\Users\Aaron\AppData\Local\Temp\ccgh3MfS.o:ostest.c:(.text+0x11): undefined reference to `fork'
C:\Users\Aaron\AppData\Local\Temp\ccgh3MfS.o:ostest.c:(.text+0x22): undefined reference to `wait'
collect2: ld returned 1 exit status
我确定我遗漏了一些小事。任何想法?
I'm sure I'm missing something trivial. Any ideas?
推荐答案
链接器找不到标准C库。
The linker can't find the standard C libraries.
您是否以正常方式安装Cygwin? (这里有一个简单的指南: http://www.eecg.utoronto.ca/ 〜aamodt / ece242 / cygwin.html )。
Did you install Cygwin in the normal way? (Here's a simple guide: http://www.eecg.utoronto.ca/~aamodt/ece242/cygwin.html).
您可以编译更简单的程序:
Have you been able to compile even simpler programs:
#include <stdio.h>
int main(int argc, char **argv) {
printf("Found C library.\n");
}
如果不编译,你可能只是试图删除并重新安装Cygwin - 有东西坏了。
If that doesn't compile, you might just want to try removing and reinstalling Cygwin - something is broken.
这篇关于使用cygwin中的fork编译程序问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!