10

I am getting these errors when I am compiling my code. I have all the headers under user/include

g++ -Ip_appmanager/inc -Icore/inc p_appmanager/src/appmanager_process.cpp -o p_appmanager/obj/appmanager -lpthread -lparser
p_appmanager/src/appmanager_process.cpp: In function ‘int main(int, char**)’:
p_appmanager/src/appmanager_process.cpp:33:21: error: ‘getpid’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:101:19: error: ‘fork’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:105:70: error: ‘execl’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:109:19: error: ‘getppid’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:124:19: error: ‘fork’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:128:61: error: ‘execl’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:132:19: error: ‘getppid’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:147:19: error: ‘fork’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:151:73: error: ‘execl’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:155:19: error: ‘getppid’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:170:19: error: ‘fork’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:175:70: error: ‘execl’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:179:19: error: ‘getppid’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp: In function ‘void* pingThread(void*)’:
p_appmanager/src/appmanager_process.cpp:302:11: error: ‘sleep’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp: In function ‘void* fifoThread(void*)’:
p_appmanager/src/appmanager_process.cpp:815:22: error: ‘fork’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:818:72: error: ‘execl’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:842:64: error: ‘execl’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:865:72: error: ‘execl’ was not declared in this scope
make: *** [all] Error 1

my kernel version is "Linux amit-bhaira 3.8.0-26-generic #38-Ubuntu SMP Mon Jun 17 21:46:08 UTC 2013 i686 i686 i686 GNU/Linux" . Same code is running on another linux machine.

please help me to fix this problem.

Thanks.

6
  • Is your code including <unistd.h>? Commented Jul 24, 2013 at 14:30
  • 1
    Do you honestly believe we can magically solve your compiler errors without seeing the code? Commented Jul 24, 2013 at 14:31
  • 1
    @H2CO3: For those particular ones, yes. Commented Jul 24, 2013 at 14:31
  • If you have the proper man pages installed you can get most info with eg man getpid or another function you use. The manual will tell you which header to include and optional linking info. Commented Jul 24, 2013 at 14:32
  • @IgnacioVazquez-Abrams Wrong attitude. Commented Jul 24, 2013 at 14:33

3 Answers 3

58

Add #include <unistd.h>

It works on other platforms because they are compiling with an old version of gcc (<4.7) which accidentally included unistd.h in some system headers.

Sign up to request clarification or add additional context in comments.

Comments

6

From the fork(2) man page:

SYNOPSIS
       #include <unistd.h>

From the exec(3) man page:

SYNOPSIS
       #include <unistd.h>

From the getpid(2) man page:

SYNOPSIS
       #include <sys/types.h>
       #include <unistd.h>

From the sleep(3) man page:

SYNOPSIS
       #include <unistd.h>

Comments

3

You have forgotten #include <unistd.h> in your program.

2 Comments

no i don't, i have mentioned that the same code is running on another linux machine.
It is probably being sucked in by some other header file - this does happen. Since your code is intentionally using things like fork and execl, you should include it yourself, and not rely on it being included indirectly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.