Help with fork command

Hey all,

Having trouble compiling c++ written code due to a fork() command issue. I am working in Code::Blocks with the GNU GCC Compiler.

Here is my code:

#include <iostream>
#include <string>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>

using namespace std;

int main()
pid_t pid;
pid = fork();

return 0;

Even code that simple won't compile. The error that prints is "undefined reference to 'fork'". This is usually due to not linking the appropriate library where the command is defined but I thought that was the 'unistd.h' library. Any suggestions?
That error is not a compile time error, but rather a linker error.
The linker can't find fork in any of the object libraries supplied (if any).
Check your linker instructions.
Last edited on
Topic archived. No new replies allowed.