开发者

Problem compiling program using fork in cygwin

开发者 https://www.devze.com 2023-04-06 00:16 出处:网络
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.

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;
}

Compiled using: gcc -Wall -Wextra -o test.o test

I get the following error:

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'
co开发者_如何学编程llect2: ld returned 1 exit status

I'm sure I'm missing something trivial. Any ideas?


The linker can't find the standard C libraries.

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");
}

If that doesn't compile, you might just want to try removing and reinstalling Cygwin - something is broken.


C:\Users\Aaron\AppData\Local\Temp\ccgh3MfS.o is a Windows-style path. If you're using Cygwin, you only be seeing Cygwin-style paths, perhaps something like /cygdrive/C/Users/Aaron/AppData/Local/Temp/ccgh3MfS.o.

You said your command line was

gcc -Wall -Wextra -o test.o test

but it was probably

gcc -Wall -Wextra -o test.o test.c

Are you invoking gcc from the Cygwin command line? What does type gcc say?


It seems that MinGW gcc is being invoked because the cygwin gcc package is not installed.

You can verify that by calling the "cygcheck -c" in the cygwin commandline which will list all the installed packages, if you can't find the gcc in the list you need to install it

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号