NO

Author Topic: adding header files  (Read 9457 times)

Shiatzu

  • Guest
adding header files
« on: October 19, 2008, 02:10:27 AM »
hi too all, i know it's been asked before and i searched it but still can't understand how to create header files.

i started a new win32 console project, and i'm trying to add a file. i can't add header files only source files.

i've tried to create the source file and then include a header with the same name ( like #include "something.h"  in something.c) and "update all dependencies" but no luck.

thanks in advance guys.




severach

  • Guest
Re: adding header files
« Reply #1 on: October 19, 2008, 08:50:53 AM »
You create header files with an editor. In the IDE File New Source Code, File Save As, Header File, ... would work fine. I usually copy or save as from another source file.

Header files are not added or removed from Pelles projects by the user. They are added and removed automatically when the IDE decides to scan for dependencies or when you select "update all dependencies."

The .h file must exist and be referenced from a .c file for the IDE to add it to the project. Create the .h file then do all those things and I think you'll see success.

Shiatzu

  • Guest
Re: adding header files
« Reply #2 on: October 19, 2008, 05:21:21 PM »
i was used to vstudio and to create the header file and it would create the source automatically.

everything working now. thanks severach 8)

smallholder

  • Guest
Re: adding header files
« Reply #3 on: October 26, 2008, 02:11:24 PM »
You create header files with an editor. In the IDE File New Source Code, File Save As, Header File, ... would work fine. I usually copy or save as from another source file.


That only works for a header file to use with the specific project you're working on. How do you create a header file that can be referenced in multiple projects?

severach

  • Guest
Re: adding header files
« Reply #4 on: October 26, 2008, 09:23:11 PM »
File Save As does not include the new header file in your current project. Placing its #include into one of the current project's C source files is what does it. You can include that header into any source file of any project you want after placing it in a suitable folder.

smallholder

  • Guest
Re: adding header files
« Reply #5 on: October 27, 2008, 09:21:25 PM »
Say I'm in a project "project1" where I have created the file "metric.h" in the way that you have described. Placing the statement #include "metric.h" in the "main.c" file of project1 then works.

However, if I now create another project "project2", and write the statement #include "metric.h" in its "main.c" file, it doesn't work.

How can I reference the file "metric.h" in project2?

Offline Robert

  • Member
  • *
  • Posts: 245
Re: adding header files
« Reply #6 on: October 27, 2008, 09:46:34 PM »
1. Open up the Project Options dialog from the menu item Projects\Options.

2. Click on the Folders tab.

3. In the folders dialog click on "includes" in the Type drop down.

4. Click on the New Folder icon.

5. In the Browse for Folder dialog navigate to the folder containing the metric.h file.

6. Click the OK button.

Robert Wishlaw

severach

  • Guest
Re: adding header files
« Reply #7 on: October 28, 2008, 04:53:44 AM »
POIDE creates each project in the folder of the same name. PROJECT1\PROJECT1.PPJ and PROJECT2\PROJECT2.PPJ. If #include "metric.h" works from Project1 then you or something has placed it into the PROJECT1 folder. #include "metric.h" won't work from project2 since the folder of project2\main.c is the only folder other than the include path that is searched for the file. You can

* Create another metric.h that references the first metric.h #include "..\project1\metric.h"
* Copy metric.h over to the PROJECT2 folder.
* Add the folder where metric.h is into the include path list.
* Move all the project's files into the same folder.
* Create another folder which both projects can access and specify the path to it. #include "..\metric\metric.h".

The first 3 options are lousy. The 4th option may be ok for small projects. The last option is the best since it is the only one that scales to any size project.

smallholder

  • Guest
Re: adding header files
« Reply #8 on: October 29, 2008, 06:46:29 PM »
Thank you. I'll try that at the weekend.