Linux 编译时出错?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17836865/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 00:21:43  来源:igfitidea点击:

Getting errors while compiling?

c++linuxubuntu

提问by Amit Bhaira

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.

我的内核版本是“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 机器上运行。

please help me to fix this problem.

请帮我解决这个问题。

Thanks.

谢谢。

采纳答案by Oliver Matthews

Add #include <unistd.h>

添加 #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.

它适用于其他平台,因为它们正在使用旧版本的 gcc (<4.7) 进行编译,该版本意外地将 unistd.h 包含在某些系统头文件中。

回答by Mats Petersson

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

你已经忘记#include <unistd.h>了你的程序。

回答by Ignacio Vazquez-Abrams

From the fork(2)man page:

fork(2)手册页:

SYNOPSIS
       #include <unistd.h>

From the exec(3)man page:

exec(3)手册页:

SYNOPSIS
       #include <unistd.h>

From the getpid(2)man page:

getpid(2)手册页:

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

From the sleep(3)man page:

sleep(3)手册页:

SYNOPSIS
       #include <unistd.h>