headers

Started by
7 comments, last by stroma 18 years, 10 months ago
hi, i am making a math lib. i write a MathHdr.h file which includes all necessery header files and defines for the lib. and i tried to used it with vector.h file; i type #include "mathhdr.h" but it did not complie because cannot include any of include files in the mathhdr.h, because _MATHHDR_H_ already defined. (i use ifndef and define keywords at the top of the header files) (i used main header because i do not want to include "matrix", "plane".. etc, every time) i see some programs use the same system, bu mine did not worked. should i use procomplied headers? how? pragma hdrstop? any suggestions? thx..
+-+-+-+-+-STR
Advertisement
Suggestions:

1. Try throwing '#pragma once' in the header
2. You didn't mention it but did you have the ifndef's endif at the end of the header file
3. Clean rebuild.

You should be able to include anything you want anywhere any number of times if you have the inclusion guards set correctly.

Thats all i can think of,

ace
thanks for quick answer
1- to main header? i mean mathhdr.h? isnt it the same thing with ifndef x define x "code" endif ? (didnt solve either)
2-of course
3-i always doing that.

what is "inclusion guards"_?
+-+-+-+-+-STR
Hello stroma,

you mean you did this

#ifndef _MATHHDR_H_
#define _MATHHDR_H_

#incldue <vecotr>
etc

...


#endif /* to end the ifndef _MATHHDR_H_ code*/

you should be able to include this anywere.
You aren't defining _MATHHDR_H_ somewere else are you?
visual studio can define the classes, i mean if i move cursor to a class mermber, it says where it defined, but when compling it says undefined for same object. :? isnt that strange?
+-+-+-+-+-STR
Quote:Original post by Lord Bart
Hello stroma,

you mean you did this

#ifndef _MATHHDR_H_
#define _MATHHDR_H_

#incldue <vecotr>
etc

...


#endif /* to end the ifndef _MATHHDR_H_ code*/

you should be able to include this anywere.
You aren't defining _MATHHDR_H_ somewere else are you?

yes i use the same. but my files cannot include the include files in mathhdr.
edit: i mean if i say include "mathhdr.h" in one file, that file cannot define the vector classes and says undefined.
+-+-+-+-+-STR
Is the path to MathHdr.h in the compile line do you see -I with the path were it lives, eats and sleeps.

Lord Bart :)
Quote:Original post by stromai type #include "mathhdr.h" but it did not complie because cannot include any of include files in the mathhdr.h, because _MATHHDR_H_ already defined.


Are you defining _MATHHDR_H_ in each header? It should be unique for one header file. Each header file should have a different name defined.
Quote:Original post by petewood
Quote:Original post by stromai type #include "mathhdr.h" but it did not complie because cannot include any of include files in the mathhdr.h, because _MATHHDR_H_ already defined.


Are you defining _MATHHDR_H_ in each header? It should be unique for one header file. Each header file should have a different name defined.

there are no "__MATH_MATHHDR_H__" expect :
#ifndef __MATH_MATHHDR_H__#define __MATH_MATHHDR_H__...includes..... defines......#endif /* __MATH_MATHHDR_H__ */


what about precomplied headers? what r they for? i have never used them, can it solve this?
+-+-+-+-+-STR

This topic is closed to new replies.

Advertisement