0

I'm trying to translate a c-code written for linux to c-code for windows. When trying 'make', it says

implicit declaration of function 'fork'

So I searched the internet, found this: What is the closest thing Windows has to fork()? Downloaded Cygwin and installed it and tried 'make' again, it spits out the same error-output. After that, I copied my c project into the cygwin folder, opened the 'cygwin-terminal'-program and run 'make' in it, still same error-output. After that I copied 'cygwin1.dll' from cygwin bin folder into my project folder and changed my Makefile to

gcc -g -Wall -Wextra -Werror -o test_open cygwin1.dll main.c dictionary.c config.c tools.c

then start 'make' again in normal terminal, but it still spits out implicit declaration error.

Have you any suggestions, what I can try next to get fork() to compile?

Includes are:

#include<sys/types.h>
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<stdbool.h>
#include<stdarg.h>
#include<errno.h>
#include<signal.h>
  • This usage of cygwin1.dll `gcc -g -Wall -Wextra -Werror -o test_open cygwin1.dll main.c dictionary.c config.c tools.c` makes no sense. What do you mean for `normal terminal` ? Why not the `Cygwin Terminal` and what is different ? Can you repeat the `cygcheck -f /usr/include/unistd.h` there ? – matzeri May 30 '20 at 03:34

1 Answers1

0

Fork requires the header

#include <unistd.h>

https://pubs.opengroup.org/onlinepubs/9699919799/functions/fork.html

that is contained in the cygwin-devel package

$ cygcheck -f /usr/include/unistd.h
cygwin-devel-3.1.4-1

Using example code from https://www.geeksforgeeks.org/fork-system-call/

#include <stdio.h> 
#include <sys/types.h> 
#include <unistd.h> 
int main() 
{ 

    // make two process which run same 
    // program after this instruction 
    fork(); 

    printf("Hello world!\n"); 
    return 0; 
} 

compiled and run with

$ gcc prova.c -o prova

$ ./prova
Hello world!
Hello world!
matzeri
  • 8,062
  • 2
  • 15
  • 16
  • 'cygcheck -f /usr/include/unistd.h' outputs 'cygwin-devel-3.1.4-1' but it still seems to not use that cygwin unistd when compiling with gcc in the cygwin terminal. There is still error: implicit declaration of function 'fork' [-Werror=implicit-function-declaration] int childIdF = fork(); – Frank Pirata May 29 '20 at 17:40
  • what is the compiler that you are using ? Are you sure you are using cygwin make and gcc ? Copy and paste command lines and commands outputs – matzeri May 29 '20 at 18:25