LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-21-2012, 02:55 PM   #1
mnowhere
LQ Newbie
 
Registered: Jul 2012
Posts: 7

Rep: Reputation: Disabled
How headers are included though the path is not showing the header folder


I have written a simple helloworld.c to print "hello world" message.
This uses stdio.h file which is located /usr/include/. my path does not include the path /usr/include at all then how does the gcc picks stdio.h when i compile d source.
 
Old 07-21-2012, 02:59 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Your path tells the system where to look when you run a command----including running gcc. When gcc is running, it has its own path definition telling it where to find things.
 
Old 07-21-2012, 11:25 PM   #3
mnowhere
LQ Newbie
 
Registered: Jul 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pixellany View Post
When gcc is running, it has its own path definition telling it where to find things.
How can I see the gcc's path definition? If I need to have one header file to be defined in the gcc's path how can I do it?
 
Old 07-22-2012, 05:07 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Look for some kind of configuration file---I assume this would be in /etc, but it could also be in your ~ directory.

Brute force method:
Run this as root:
Code:
find / -name "*gcc*conf"
or maybe
find / -name "*gcc*cfg"
But doesn't gcc also have some command options for setting things up? e.g. try "man gcc"
 
Old 07-22-2012, 06:31 AM   #5
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
http://gcc.gnu.org/ml/gcc-help/2007-09/msg00204.html

Also, note that sometimes you do have to tell gcc (well, technically the preprocessor) where to find headers and libraries. You do this with the -I and -L options, respectively.
 
Old 07-22-2012, 07:29 AM   #6
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
Quote:
Originally Posted by mnowhere View Post
... If I need to have one header file to be defined in the gcc's path how can I do it?
If you're talking about your own header files, you can put them in the same directory as your code; they are, after all, part of your project.
Code:
+
|
+-- yourproject
       |
       +-- main.c
       +-- somefile.c
       +-- someinclude.h
And in main.c and/or somefile.c, you can simply include someinclude.h and the compiler will find them.
 
Old 07-31-2012, 02:39 PM   #7
mnowhere
LQ Newbie
 
Registered: Jul 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thnq Nylex and everyone,

The following link,
http://gcc.gnu.org/ml/gcc-help/2007-09/msg00204.html
explains about the include path very well, the include path for the header files is taken care by preprocessor(cpp) and not the compiler(gcc)
so executing "cpp -v" on command prompt will give u the list of paths where the c preprocessor looks for header files by default.

But how to edit this path is still being mystery for me, I am expecting some help from u guys..
 
Old 07-31-2012, 02:41 PM   #8
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Why can't you use the -I option to specify additional directories?
 
Old 08-01-2012, 02:39 AM   #9
mnowhere
LQ Newbie
 
Registered: Jul 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Nylex View Post
Why can't you use the -I option to specify additional directories?
There is no problem in doing dat.. Its just for the sake of my knowledge.. jus wanted to kno if I change or add the header file path..
 
Old 08-05-2012, 07:02 AM   #10
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
I think (but am not at all certain) that the directories are specified when the compiler is built, so you have to use the -I option.

Also, per the LQ rules, please avoid "SMS" speak and write out your words in full.
 
Old 08-07-2012, 03:34 AM   #11
mnowhere
LQ Newbie
 
Registered: Jul 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
I am extremely sorry for those SMS kind of messages it has became a habit for me
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
C++, order of included header files in inheritance? michaelinux Programming 2 01-18-2012 03:02 PM
Command to list headers included in a .ko files theoutkast Programming 6 07-11-2011 11:12 AM
How to check missing header files included from another header file adisan82 Linux - Software 1 01-28-2011 04:57 AM
How to compile a C program in Glade which is included the <pcap.h> header file. swaviswa Programming 0 03-21-2004 08:47 AM
math.h and other included header files ecc6 Slackware 1 04-19-2003 03:15 PM


All times are GMT -5. The time now is 06:27 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration