Thread: How to add more header files?

  1. #1
    Registered User
    Join Date
    Oct 2014
    Posts
    10

    How to add more header files?

    Hello, I'm a beginner with C and wonder how to include single header files (*.h) in to my project. I mean header files which are not included to the standard installation package.

    I thought it would work if I just copy the newheader.h file in to library folder c:\MinGW\include\, but it didn't work. Is there some kinf of GCC -command or procedure to add these single header files or how it should work?


    All of those standard header files are working well and I don't have any problems with them.

    Environment I'm using is MinGW+GCC+Win7.

    Thanks

    - j

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Code which uses a function in a header file needs to #include that header file. If it doesn't, it does not matter in the slightest where you place the header files.

    Common technique is to place the header files that are specific to your project in the same directory as source files (with .c extension). Since the source files will #include the header files as needed, it is not otherwise necessary to register header files in your project.

    There are other techniques but, if you can't get the most basic "vanilla" approach down (that works regardless with all compilers unless you do something really funky to confuse things), you shouldn't be using those.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Oct 2014
    Posts
    11
    Hi Jamorp, you'll have to use double quotes for the header file inclusion even if you included it in the "c:\MinGW\include" folder, since it does not belong to that IDE/Compiler's standard installation package, like for example, if I had a header file called greetMe.h, after including it it in the "c:\MinGW\include" folder, I add it like this:

    Code:
    #include "greetMe.h"
    If you did not put it in that "MinGW\include" folder, however, you'll have to specify the full path like this:

    Code:
    #include "c:\users\admin\documents\My custom headers\greetMe.h"
    Have fun! and when you're ready check this out:

    Sudoku Program in "C"
    Last edited by Suigen; 10-02-2014 at 03:08 AM. Reason: Correction

  4. #4
    Registered User
    Join Date
    Oct 2014
    Posts
    10
    ..double quotes, thanks Suigen, this helped me one step further. Instead of "No such file or directory" I've got now this error message below, which makes me wonder if third-party "bintree.h" is incompatible with my setup:

    c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libmingw32.a(main.o):main.c.text.startup+0xa7): undefined reference to `WinMain@16'collect2.exe: error: ld returned 1 exit status

  5. #5
    Registered User
    Join Date
    Oct 2014
    Posts
    11
    Quote Originally Posted by jamorp View Post
    ..double quotes, thanks Suigen, this helped me one step further. Instead of "No such file or directory" I've got now this error message below, which makes me wonder if third-party "bintree.h" is incompatible with my setup:
    Some IDEs/compilers come with an "include32" folder and another "include" folder (you can do a type search for these folders in the software's main directory), for example Dev C /MinGW GCC compiler, if your version of that IDE is a 32-bit release, be sure to include your header file into the include32 folder as it will default to that folder, unless you specify other wise. Please keep me posted.

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by Suigen View Post
    Hi Jamorp, you'll have to use double quotes for the header file inclusion even if you included it in the "c:\MinGW\include" folder, since it does not belong to that IDE/Compiler's standard installation package, like for example, if I had a header file called greetMe.h, after including it it in the "c:\MinGW\include" folder, I add it like this:
    Clearly, you don't understand the point that it is not necessary and definitely not recommended that additional headers be placed in an implementation's include path.

    Quote Originally Posted by Suigen View Post
    If you did not put it in that "MinGW\include" folder, however, you'll have to specify the full path like this:
    It is only necessary to specify a full path if you don't understand how the compiler finds user specified header files (i.e. those with names in double quotes).

    If you need to fully specify paths of headers, then you are missing the point of header files.

    Quote Originally Posted by jamorp View Post
    ..double quotes, thanks Suigen, this helped me one step further. Instead of "No such file or directory" I've got now this error message below, which makes me wonder if third-party "bintree.h" is incompatible with my setup:
    That error message is from the linker, and has nothing to do with the compiler, let alone header files. It results from building a standard C program - one that has a main() function - as a windows program. Look up compiler, library, or development options, and find the settings to build a "Console application" or similar (the precise wording depends on development environment).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  7. #7
    Registered User
    Join Date
    Oct 2014
    Posts
    11
    Jamorp, Grumpy is right. You should include your header files which are specific to your project in your project folder, i.e the one which houses your .c source file just like Grumpy said for portability to another person's computer for example.

    Grumpy, my bad, I should have suggested setting up his IDE/compiler to look from header files from a specific path and caching them, but because Jamorp said he/she was a beginner, he would need to understand his IDE/Compiler properly.

    Jamorp, you can google: "How to set up <insert IDE/Compiler's name> to find header files from different path" as I do not know your Implementation software.

    Jamorp, be sure that you are not building a Windows/Win32 project if your intention was to create a console application (Because their "main( )" function and function calls are different).
    Last edited by Suigen; 10-02-2014 at 05:42 AM. Reason: Correction

  8. #8
    Registered User
    Join Date
    Oct 2014
    Posts
    11
    Please, keep me posted.
    Last edited by Suigen; 10-02-2014 at 05:44 AM. Reason: Correction

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with Header Files and Source files
    By yukapuka in forum C Programming
    Replies: 3
    Last Post: 10-10-2012, 01:57 AM
  2. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  3. Replies: 4
    Last Post: 12-14-2005, 02:21 PM
  4. include library header in header files
    By Raison in forum C++ Programming
    Replies: 6
    Last Post: 09-27-2004, 02:50 AM
  5. header files and code files..
    By CompiledMonkey in forum C++ Programming
    Replies: 4
    Last Post: 02-15-2002, 09:35 AM