LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 10-27-2004, 06:21 PM   #1
apocolpse
Member
 
Registered: Oct 2004
Distribution: Fedora Core 4
Posts: 91

Rep: Reputation: 15
gcc include


I'm quite new to linux (Gave up on windows), and thus new to linux progamming on a whole, so please bear with me for a minute. I had a programming assignment to do in c. it includes <unistd.h>. It compiles on the school machine, but in mine @ home i get


cphillip1.c:7: error: `pid_t' undeclared (first use in this function)
cphillip1.c:7: error: (Each undeclared identifier is reported only once
cphillip1.c:7: error: for each function it appears in.)
cphillip1.c:7: error: parse error before "pid"
cphillip1.c:11: error: `pid' undeclared (first use in this function)
cphillip1.c:15: error: `my_pid' undeclared (first use in this function)
cphillip1.c:29:7: warning: no newline at end of file


I'm guessing that the include path cannot be found. I use gcc to compile. how can I set the class path so that gcc knows where the include is without having to use a command line switch. ?? I'm running SUSE 9.1 Gnome 2.8 / KDE 3.3. Details please (remember I'm new) and please ... be nice.
 
Old 10-27-2004, 07:15 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 56
There are no class paths (or classes at all for that matter) in C. unistd.h should contain the definition for pid_t. Could you post the code?
 
Old 10-28-2004, 10:06 AM   #3
apocolpse
Member
 
Registered: Oct 2004
Distribution: Fedora Core 4
Posts: 91

Original Poster
Rep: Reputation: 15
#include <unistd.h>

main() {

pid_t pid, my_pid; /* variable for process-id */

printf("Calling fork...\n");

pid = fork(); /* create a new process */

if(pid == 0) { /* am I the child process? */

my_pid = getpid();

printf("I'm the child, my pid is %d\n", my_pid);


}

else if(pid > 0) /* or am I the parent? */

printf("I'm the parent, child has pid %d\n", pid);

else /* or did something go wrong */

printf("fork returned error code, no child\n");
}
 
Old 10-28-2004, 10:08 AM   #4
apocolpse
Member
 
Registered: Oct 2004
Distribution: Fedora Core 4
Posts: 91

Original Poster
Rep: Reputation: 15
If there are no paths, then why doesn't gcc see or recognise pid_t ??
 
Old 10-28-2004, 10:45 AM   #5
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 56
You're missing sys/types.h include.

From man fork:
Code:
SYNOPSIS
       #include <sys/types.h>
       #include <unistd.h>

       pid_t fork(void);
You're also not including stdio.h for printf().
 
Old 11-01-2004, 07:06 PM   #6
apocolpse
Member
 
Registered: Oct 2004
Distribution: Fedora Core 4
Posts: 91

Original Poster
Rep: Reputation: 15
so then why does it compile on the other machine and not on mine then with the same code ??
 
Old 11-03-2004, 01:36 PM   #7
sheds
Member
 
Registered: Oct 2004
Location: Costa Rica
Distribution: Mandrake 9.1
Posts: 30

Rep: Reputation: 15
That's a good question. Sometimes, when you compile again, you have to make a "touch" to the file you just compiled, i will do some research to see if this helps out. I've seen it done be4 but i am not sure how it works.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add boost libraries to gcc include list kiku Linux - Newbie 1 03-04-2005 02:49 PM
gcc on 9.1 include problem skywarp Slackware 3 06-04-2004 10:05 PM
GCC:- 'cout' is an undeclared function when #include <iostream> is included? caesius_01 Programming 5 04-04-2004 11:00 AM
gcc STL include problem finidi Programming 3 01-14-2003 06:55 AM
GCC include path. jwilson Linux - General 1 04-02-2001 03:58 PM


All times are GMT -5. The time now is 02:21 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration