2013-07-24 177 views
6

我在編譯我的代碼時遇到這些錯誤。我都下用戶頭/包括編譯時出錯?

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 

我的內核版本是「Linux的阿米特 - bhaira 3.8.0-26泛型#38,Ubuntu的SMP週一6月17日21時46分08秒UTC 2013 i686的的i686 i686的GNU/Linux「。相同的代碼在另一臺linux機器上運行。

請幫我解決這個問題。

謝謝。

+0

是您的代碼,包括? –

+1

你是否誠實地相信我們可以神奇地解決你的編譯器錯誤而不看代碼? – 2013-07-24 14:31:23

+1

@ H2CO3:對於*那些*特定的,是的。 –

回答

40

添加#include <unistd.h>

它適用於其他平臺,因爲它們與舊版本,在某些系統頭不小心unistd.h中包括GCC(< 4.7)的編制。

2

您忘記了您的程序中的#include <unistd.h>

+0

不,我沒有,我已經提到相同的代碼在另一臺Linux機器上運行。 –

+1

它可能被其他頭文件吸引 - 這確實發生。由於你的代碼有意使用諸如'fork'和'execl'之類的東西,你應該自己包含它,而不要依賴它被間接包含。 –

6

fork(2)手冊頁:

SYNOPSIS 
     #include <unistd.h> 

exec(3)手冊頁:

SYNOPSIS 
     #include <unistd.h> 

getpid(2)手冊頁:

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

sleep(3)手冊頁:

SYNOPSIS 
     #include <unistd.h>