#import and .h files problem
I have 2 .h files
I use them in 2 classes and I import using #import.
I get duplicate function linker errors. The functions in each.h are not the same but its acting like the #import is not blocking the double include. I even tried #ifndef lock around it and it didn't help.
Does anyone know whats going on? The 2 functions in question are:
Vector3f Vector3f_create(CGFloat x, CGFloat y, CGFloat z)
Vector2f Vector2f_create(CGFloat x, CGFloat y)
I use them in 2 classes and I import using #import.
I get duplicate function linker errors. The functions in each.h are not the same but its acting like the #import is not blocking the double include. I even tried #ifndef lock around it and it didn't help.
Does anyone know whats going on? The 2 functions in question are:
Vector3f Vector3f_create(CGFloat x, CGFloat y, CGFloat z)
Vector2f Vector2f_create(CGFloat x, CGFloat y)
kendric Wrote:but its acting like the #import is not blocking the double include
This actually doesn't help you here. If you import this header from more than one implementation file, you end up with multiple definitions of the functions declared in the header, since the implentation files are compiled in separate modules. Since #import is essentially just a copy-and-paste operation, each module gets its own copy of the functions, so the linker complains that there are multiple definitions when it stitches your object files together.
A simple solution is to add the static qualifier to the functions in the header. All function implementations in header files that may be included from more than one module must be static for exactly this reason.
Thank you much! This solved the problem!
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| import explosion | 9livesoftware | 0 | 1,736 |
Aug 8, 2009 04:25 PM Last Post: 9livesoftware |
|

