LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   *.h files....where to put them for #include (https://www.linuxquestions.org/questions/programming-9/%2A-h-files-where-to-put-them-for-include-49370/)

centr0 03-11-2003 10:27 PM

*.h files....where to put them for #include
 
i have *.h files that i want to access when writing in c. i run redhat 8 and was wondering where should i put the files?

thanks for your help
=]

acid_kewpie 03-12-2003 03:39 AM

these are header files you have just created yourself? you can specify code to use a local relative path by using #include "header.h" rather than #include <header> this will then look for the h file in your current directory.

llama_meme 03-12-2003 08:57 AM

If you want to have the header files in a different directory, you might find it easier to use the -I[include dir] option of gcc and <> brackets in the #include. This way, you don't have to keep typing the full path of the header in your source files.

Alex

Dark_Helmet 03-12-2003 10:51 AM

I would suggest using acid_kewpie's route. When you start writing for a new project, create a directory for it, then an "include" subdirectory. Any header files you create can be referenced like:

#include "include/header.h"

llama_meme's suggestion will work too. If you revisit the code later though, you may not remember header files were included on the command line. It's not intuitive (for me at least) to look there for it.

Tinkster 03-12-2003 05:24 PM

Quote:

quoting Dark_Helmet
It's not intuitive (for me at least) to look there for it.
Of course one could use Makefiles and look at them
when trying to re-use code ;)

Cheers,
Tink

Dark_Helmet 03-12-2003 05:45 PM

Yep, Makefiles are great.

I'm quite <ahem> retentive though when it comes to programming style. Something about a computer science instructor, a LARGE crowbar, and lots of bruises... it's all kind of blurry... can't imagine why... but I digress...

I just can't convince myself to remove the paths from include statements. When I look at source code and come across something (like a typedef, #ifdef statements, and the like), then I like to jump to the top of the file and know exactly where to look for where all that stuff is defined. Ease of access to information... it's all about fewer files to look in... :)

centr0 03-13-2003 05:45 AM

whats the default directory the compiler looks in for '#include <blah.h>'

im just learning C going very slowly. bare with me. =)

llama_meme 03-13-2003 06:26 AM

Depends on how your system is set up. The only one you can be sure of is /usr/include.

Alex


All times are GMT -5. The time now is 01:25 PM.