Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting errors while compiling?

Tags:

c++

linux

ubuntu

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.

like image 472
Amit Bhaira Avatar asked Jul 24 '13 14:07

Amit Bhaira


People also ask

What causes compilation errors?

A compile error happens when the compiler reports something wrong with your program, and does not produce a machine-language translation. You will get compile errors.

What type of error do you get while compiling your program?

Syntax errors, linker errors, and semantic errors can be identified by the compiler during compilation. Logical errors and run time errors are encountered after the program is compiled and executed.

Can errors occur at compile time?

A compile-time abend can indicate an error in the compiler. An unsuccessful compilation due to an error in the source code or an error from the operating system should result in error messages, not an abend. However, the cause of the compiler failure may be a syntax error or an error from the operating system.


3 Answers

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.

like image 106
Oliver Matthews Avatar answered Oct 21 '22 02:10

Oliver Matthews


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>
like image 39
Ignacio Vazquez-Abrams Avatar answered Oct 21 '22 04:10

Ignacio Vazquez-Abrams


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

like image 3
Mats Petersson Avatar answered Oct 21 '22 03:10

Mats Petersson