我在编译代码时遇到这些错误。我在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
我的内核版本是“Linux amit-bhaira 3.8.0-26-generic#38-Ubuntu SMP Mon Jun 17 21:46:08 UTC 2013 i686 i686 i686 GNU / Linux”。相同的代码在另一台Linux机器上运行。
请帮我解决这个问题。
感谢。
答案 0 :(得分:47)
添加#include <unistd.h>
它可以在其他平台上运行,因为它们正在使用旧版本的gcc(&lt; 4.7)进行编译,它在某些系统头文件中意外地包含了unistd.h。
答案 1 :(得分: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>
答案 2 :(得分:3)
您已忘记程序中的#include <unistd.h>
。